File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP and Javascript problem" Watch "JSP and Javascript problem" New topic

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">
<input type="text" name="ssn" value="<%=request.getAttribute("ssn")%>" size="9" maxlength="9">
var testssn = register_form.ssn.value;
alert("Please fill in the ssn");
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
I agree. Here's the link:
subject: JSP and Javascript problem
It's not a secret anymore!