0

I am trying to use the JQuery Ui function "Verfiy();" to verify that the name, age, country and date fields have been filled before allowing the form to submit.

The verify function should be called when the user hits 'submit', however when I use the following code the webpage is directed to the 'thankyou' page whether the fields have been completed or not. It does not show an error message.

<head>

...

<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Wayne Nolting (w.nolting@home.com) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://www.javascriptsource.com -->

<!-- Begin

function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.form.name.value=="") {
themessage = themessage + " - Name";
}
if (document.form.age.value=="") {
themessage = themessage + " - Age";
}
if (document.form.country.value=="") {
themessage = themessage + " - Country";
}
if (document.form.date.value=="") {
themessage = themessage + " -  Date";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
   }
}
//  End -->
</script>

</head>



<body>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>


...

 <input type="submit" value="Submit" onClick="verify()"/></div>
 <input type=reset value="Clear Form"><br>

...

</body>

Any insight would be greatly appreciated.

Andrew

Andrew Smith
  • 310
  • 3
  • 6
  • 19

1 Answers1

0

Here you go, just a little tweak in your markup.

<input type="submit" value="Submit" onClick="return verify()"/></div>
GeForce
  • 90
  • 1
  • 8