The reason both alerts are not firing (if your elements are referenced correctly) is because you are executing return false;
in each if. This prevents any more code from firing in the function, and so the second if
does not have a chance to fire.
In my code, I have added a variable and then I return false;
at the end of the function if either if
executes. This allows both alerts to fire.
function a()
{
var submitform = true, x=document.forms["addform"]["gender"].value, y=document.forms["addform"]["count"].value;
if (x===null || x=="") {
alert("Enter gender");
submitform = false;
}
if (y===null || y=="") {
alert("enter country");
submitform = false;
}
// Added an if here
if (submitform === false) {
return false;
}
}
Thanks
Frederick
edit: using ===
is a better practice for checking for identical values. See this stackoverflow question for more.