File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes JSP and Javascript problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP and Javascript problem" Watch "JSP and Javascript problem" New topic
Author

JSP and Javascript problem

arpit singla
Ranch Hand

Joined: Jun 18, 2001
Posts: 66
I have a JSP submitting form data to servlet. One of the textfield is ssn. If sb. doesn't fills the numbers in the "ssn" textfield, i want to check that on client side using Javascript. Please let me know how to do it properly. I tried with the following code but it gives me the alert message even before that JSP having the ssn textfield is displayed.
Please let me know the correct format.
<form name="register_form">
<tr>
<td>
SSN:
<input type="text" name="ssn" value="<%=request.getAttribute("ssn")%>" size="9" maxlength="9">
<script>
var testssn = register_form.ssn.value;
if(testssn==null)
alert("Please fill in the ssn");
</script>
</td>
</tr>
</form>
thanks a lot
Detlev Beutner
Ranch Hand

Joined: Jul 13, 2001
Posts: 76
To be rude: This is not a JSP/Servlet question, it's just JavaScript...
But to be kind: It seems that first, someone has to input some "ssn"-value in the first (here not cited) page. This page calls the JSP. Then in the JSP the "ssn"-value is taken and put in a form again. Now, in your example, the JavaScript is run anyhow, before the client-side user has the possibility to edit the form again.
So, you can check the input in the first page OR in the second (JSP), by JavaScript, with the help of "onClick" or "onSubmit", for example.
Hope it helps
Detlev
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSP and Javascript problem