Forums Register Login

JSP and Javascript problem

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 945 times.
Similar Threads
web application in eclipse 9
Require help in submitting <form> through JavaScript function
validation problem in jsp
Need Help on HTML
disable other textfield as one textfield entered
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:38:49.