Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onClick & Form Verification

Status
Not open for further replies.

ironmunk

Technical User
Aug 21, 2001
51
CA
Hi, can anyone assist me with the following. I need the code to

a) once a user clicks the submit button on a form it verifies the data in the text field is valid (not null).
b) If all data entered then run php script or a pop up message will appear telling users to fillin all data fields.
 
Inside the form tag, specify an onsubmit event and call some javascript function you make to verify inputs. If you discover a problem, use "return false;" else if everything's good, use "return true;".
 
ironmunk, this is a small example of a validation script and how its used.

Code:
<html>
<head>
<script>
function validate() {
 //creates a var that holds the parameters &quot;document.myForm&quot;
 var check = document.myForm;
  //if the name field is blank
  if(check.name.value == &quot;&quot;) {
    //throw an alert
    alert(&quot;Please fill in a name&quot;);
    //put focus on the name field
    check.name.focus();
    return false;
  }
  if(check.address.value == &quot;&quot;) {
    alert(&quot;Please fill a proper address&quot;);
    check.address.focus();
    return false;
  }
}
</script>
</head>

<body>
//onSubmit calls the function, if function not satisfied alert comes, if satisfied form gets sent via the action
<form name=&quot;myForm&quot; method=&quot;post&quot; action=&quot;someform.html&quot; onSubmit=&quot;return validate();&quot;>
  Enter Name:  <input type=&quot;text&quot; name=&quot;name&quot;><br><br>
  Enter address:  <input type=&quot;text&quot; name=&quot;address&quot;><br><br><br>
  <input type=&quot;submit&quot; name=&quot;Submit Form&quot;>
</form>
</body>
</html>

I have this little thing, Advanced Delusionary Schizophrenia with Involuntary Narcissistic Rage.
It's no big deal really...
 
Glad I could help...

I have this little thing, Advanced Delusionary Schizophrenia with Involuntary Narcissistic Rage.
It's no big deal really...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top