I am having a problem with validating my form, it works if I only validate 1 field, but if I try to validate more than 1, nothing happens when I click submit
Here is my code:
function validateForm()
{
var x=document.forms[“dform”][“name”].value
if (x==null || x==“”)
{
alert(“Enter Name!”);
return false;
}
}
{
var x=document.forms[“dform”][“selling_1”].value
if (x==null || x==“”)
{
alert(“Enter Selling Name!”);
return false;
}
}
The return statement stops all code after it from being able to execute.
Instead of returning at the first sight of an error, you may want to set a variable at the start called isValid to true, and then set isValid to false when you encounter an error.
At the end of things, you can then return that isValid variable.