First time posting here, last alternative to getting even more frustrated with this non-sense. I see nothing wrong with this code segment and yet the onsubmit condition seems to be always returning as true, even if I leave the fields blank (which should be verified on the spot).
NOTE: my JS functions are blank at the moment, haven’t gotten that far yet.
Further investigation note: even the final case which I wrote to be a catch all is not working, it’s simply trying to reach the checkout page as soon as I hit submit and completely ignoring the onsubmit.
<?xml version = "1.0" encoding = "utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Book registration. </title>
<script type = "text/javascript" src = 'Script/main.js'></script>
</head>
<body>
<form method = "POST" action = "Checkout" onsubmit = "validate(this)">
<fieldset>
<legend> Book Registry Access </legend>
<p> ISBN: <input type = "text" size = "14" name = "ISBN" onchange = "if(this.value != '') ajaxVerif('checkISBN', this.value, this.id);"> </p>
<p> Title: <input type = "text" size = "32" id = "title" name = "title"> </p>
<p> Author: <input type = "text" size = "32" id = "author" name = "author"> </p>
<p> Edition: <input type = "text" size = "2" id = "edition" name = "edition" onchange = "if(this.value != '') ajaxVerif('checkEdi', this.value, this.id);"> </p>
<p> <input type = "submit"> </p>
</fieldset>
</form>
</body>
</html>
function validate(thisForm)
{
if (thisForm.ISBN.value == '') {
alert('Please enter a valid ISBN number in the form XXXX-YYYY-ZZZZ');
this.ISBN.focus();
return false;
}
if (thisForm.title.value == '') {
alert('Please fill in the title field.');
this.title.focus();
return false;
}
if (thisForm.author.value == '') {
alert('Please fill in the author field.');
this.author.focus();
return false;
}
if (thisForm.edition.value == '') {
alert('Please enter a valid edition number.');
this.edition.focus();
return false;
}
alert('Success! This test form is working! (TO BE DELETED!!)');
return false;
}
EDIT: edited for cleanliness, still cannot get it to work. So now everything works in terms of verification except, apparently, the returning false. It will always try to jump to the next page (and fail because that links to a dummy page). I am not quite sure why, pretty sure all my returns should be ok.
FINAL EDIT: Fixed, I forgot to write it as onsubmit = ‘return validate(this)’>
First, avoid inline JavaScript.
You would have noticed the missing
}by keeping a clean JavaScript code.UPDATE
You forgot the
return, andYou also forgot to finish replacing
thiswiththisForm.