I am using a jquery pluggin for a quick and easy form validation My forms use the input's default value as a label and I have a little onfocus and onblur javascript function to show and hide this when the user starts to type:
<input name='fnameREG' type='text' id='fnameREG' value='first name' size='70' onfocus='clearInput(this)' onblur='clearInput(this)' />
<input name='lnameREG' type='text' id='lnameREG' value='last name' size='70' onfocus='clearInput(this)' onblur='clearInput(this)' />
My issue with the validation is that when the submit button is clicked the pluggin thinks that all the fields are set because they have a default value. I looked but I couldn't find a supplied method to get round this. Thanks! ...Or has anyone come accross a better validation method?
And here is the .addmethod function for the pluggin which I am trying unsucessfuly to use to add a new method that checks for the default value. Any ideas???
jQuery.validator.addMethod("deflt", function(value, element) {
return this.optional(element) || value == value.defaultValue;
}, "You must enter a value");
Mark... below is my clearInput function. Yea it basically does the same as the watermark effect but I'm using this now and can't see much reason to switch. Although if I don't find another way I will use this, it would just involve deleting some markup:
function clearInput(field){
if (field.defaultValue == field.value){
field.value = '';
}
else if (field.value == ''){
field.value = field.defaultValue;
}
}