I am trying to run a form validation on an HTML form to make sure the person has filled out the two fields. I put together a JSFiddle here:
It has worked previously for me and I don’t know what’s going on now. I made a JSFiddle to pull it out of my site to make sure nothing else was conflicting with it but I’m realizing now that it’s something in the code. The two fields are name “emailaddress” and “Name” respectively and it looks like I’m checking their values correctly. Basically, I’m looking for an alert (and NOT a submittal of the form) if they’ve left either field blank. Thanks for helping me track down the problem. I appreciate it.
function ValidateForm(){
var emailID=document.MailingList.emailaddress
var nameID=document.MailingList.Name
if ((nameID.value==null)||(nameID.value=="")){
alert("Please Enter your Name");
nameID.focus();
return false;
}
if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID");
emailID.focus();
return false;
}
}
Even though there is not return true, the form still submits.
the problem is that you haven’t defined ValidateForm in the
Headsection.i have edited the jsfiddle.check demo.