| Author |
validation
|
Pritam Chatterjee
Greenhorn
Joined: Jul 31, 2011
Posts: 13
|
|
In my project i have a from which have several fields. The form is
<form name="reg" action="payment.jsp" method="post">
-----------
<tr> <td>First name:</td> <td><input type="text" name="firstname"/></td></tr>
--------------------------
<input type="submit" value="Next" onclick="fun()" />
------------
</form>
Then to validate the fields i have used JavaScript.They are validating rightly using a alert box. But when i am pressing ok of the alert box the control is passing to the page i have written in action of the form.I want when i will press ok it should come back to the same page.Only if all fields are then it should go to the page refereed in action. Can anyone help me?
The JavaScript code is
<script type="text/javascript">
function fun()
{
var x=document.forms["reg"]["firstname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
}
|
Pritam
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15362
|
|
You are not cancelling the form submission, that would be your problem. You should be using onsubmit on the form and not a click event on the button.
Eric
|
 |
 |
|
|
subject: validation
|
|
|