/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function fixFormLabels(){ var labels; // enable for IE and Safari if( document.all || navigator.userAgent.indexOf("Safari") > 0){ labels = document.getElementsByTagName("label"); for(i=0; i<labels.length; i++){ labels[i].onclick = function(){ var target = document.getElementById(this.getAttribute('for')); // Checkboxes or radio button labels if(target.type == 'checkbox' || target.type == 'radio') target.checked = target.checked == false ? true : false; else // Textareas and input fields, Select elements target.focus(); }; } } } // execute the script when the page has loaded window.onload = fixFormLabels;
URL: http://www.freshlabs.de/journal/archives/2006/10/clickable-form-labels-for-safari-and-ie/