Posts: 876
Name: Matt Pealing
Location: England, north west
|
I've used a script on this page here:
http://bit.ly/aJb439
It targets all text fields and text areas. You can see how it clears the text when you click inside a text field. If you don't type anything in there it will return to its initial value.
What I'm trying to do is set it so that the fields have a class of 'inactive' unless the user enters their own value.
Notice how it isn't working correctly! The class is removed when you start typing (as expected) but then when you click outside of the field it returns to 'inactive'.
Does anybody know what is wrong with me script??
Thanks in advance.
Code:
// clear the text in the form fields
$(document).ready(function() {
$('input:text, textarea').each(function(){
$(this).data('iVal', $(this).val());
})
.focus(function(){
if($(this).val() === $(this).data('iVal'))
$(this).val('');
$(this).removeClass('inactive');
})
.blur(function(){
if ($(this).val() === '')
$(this).val($(this).data('iVal'));
$(this).addClass('inactive');
})
});
|