This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP and Javascript problem
 
Similar Threads
web application in eclipse 9
validation problem in jsp
Require help in submitting <form> through JavaScript function
Need Help on HTML
disable other textfield as one textfield entered