/ Published in: jQuery
Show/hide labels on focus/blur when using form values as labels.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var formEl = '#main .contact_form'; if( $(formEl).length >0 ){ var labelArray = new Array(); for(i=0 ; i<$(formEl+' .inputText').length ; i++){ labelArray[i] = $(formEl+' .inputText:eq('+i+')').attr('value'); } $(formEl+' .inputText').focus( function(){ index = $(formEl+' .inputText').index(this); if( $(this).attr('value') == labelArray[index] ){ $(this).attr('value',''); } }).blur(function(){ index = $(formEl+' .inputText').index(this); if( ($(this).attr('value') == labelArray[index]) || ( $(this).attr('value') == '') ){ $(this).attr('value',labelArray[index]); } }); }