I am trying to validate a form using javascript. The text fields are embedded within table rows. A blank table row is left to display warnings (like “cannot be blank”). When I am calling the method validateForm() on onsubmit the warning appears in the table row and disappears. And when I press the button the second time then the warning stays on the html page. I don’t know whats happening.
function validateForm() {
var warnmsg = checkNames();
document.getElementById("row1").innerHTML = warnmsg;
}
function checkNames() {
var fname = document.getElementById("fname");
if (fname.value.length==0)
return "Cannot be left blank";
else
return "";
}
You must return false in order for the page not to leave.
then in your form:
here’s my test page