aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes validation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "validation" Watch "validation" New topic
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
    
    6
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: validation
 
Similar Threads
servlet or jsp page with prefilled forms
reg html tables
Regarding HTML Form
please observe this snippet
How to pass value in href tag