Can anyone advise where I’m going wrong with my form validation below?
Basically if the names variable doesn’t contain anything I want the input box to display ‘please enter your name’, but if they resubmit and still haven’t added a name I need the if statement to pick up the phrase and still not validate.
Its driving me nuts – any help gratefully received!
Cheers
Paul
if((names.length == 0) || (names != 'Please Enter Your Name')){
var error = true;
$('.error').fadeIn(500);
$('.nStar').fadeIn(500);
$('#name').val('Please Enter Your Name');
}else{
setTimeout("errorOut()",1000);
$('.nStar').fadeOut(500);
}
Your
ifstatement is checking if the value of the input is notPlease Enter Your Name. I believe you want to check if it is.This line:
Should change to:
This is assuming that the
namesvariable consists of theinputelement’s value.