Return to Snippet

Revision: 1512
at October 14, 2006 11:41 by dertimbo


Initial Code
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;

Initial URL
http://www.freshlabs.de/journal/archives/2006/10/clickable-form-labels-for-safari-and-ie/

Initial Description


Initial Title
Clickable Form Labels for Safari and IE

Initial Tags
form, ie

Initial Language
JavaScript