/ Published in: JavaScript

URL: http://www.freshlabs.de/journal/archives/2006/10/clickable-form-labels-for-safari-and-ie/
Expand |
Embed | Plain Text
function fixFormLabels(){ var labels; // enable for IE and Safari if( document.all || navigator.userAgent.indexOf("Safari") > 0){ labels = document.getElementsByTagName("label"); $A(labels).each ( function(label){ Event.observe(label, "click", function(){ var target = $(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 Event.observe(window,"load", fixFormLabels);
You need to login to post a comment.