*
The moose likes HTML, CSS and JavaScript and the fly likes Validate JSP form through JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Validate JSP form through JavaScript" Watch "Validate JSP form through JavaScript" New topic
Author

Validate JSP form through JavaScript

Samuel Castillo Romero
Greenhorn

Joined: Dec 21, 2010
Posts: 26
Hi all,

I'm trying to validate a form which is using Struts tags and I am not able to validate anything from the client side through JavaScript. Basically, this is the form that I have:



Well... every time that I click on the "Search" button the JavaScript function is not executed if I left empty the textfield named "localidad". I am not sure if I am binding\passing correctly the variable named "localidad" in to the JavaScript function or maybe the validation is wrong... or maybe I need to add any other reference in the header....

Finally, I have to say that the form is working perfectly if I fill all the fields so the problem starts if I left any empty field... those fields are not validated!!

Any suggestions?

Thanks a lot one more time for your support and apologies for the code, it is in Spanish...
-S
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

A few things: it's not a "JSP form". It's an HTML form. All of that Struts markup gets turned into plain HTML when it is sent to the browser. And that is what the JavaScript sees as well.

So looking at the server-side markup is not helpful; to you, or to us.

Do a View Source and see what the browser sees.

Also, open up the browser's JavaScript debugger and see what's going on. Are there errors? If so, what are they?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Samuel Castillo Romero
Greenhorn

Joined: Dec 21, 2010
Posts: 26
Bear Bibeault wrote:A few things: it's not a "JSP form". It's an HTML form. All of that Struts markup gets turned into plain HTML when it is sent to the browser. And that is what the JavaScript sees as well.

So looking at the server-side markup is not helpful; to you, or to us.

Do a View Source and see what the browser sees.

Also, open up the browser's JavaScript debugger and see what's going on. Are there errors? If so, what are they?


You gave me the key for making it works!! Basically, after viewing the code from the browser I could identify the real ID of the different resources of my form. Give that ID I was able to check if the field was empty or not so now it works nicely!!

Thanks a lot for your help on that
-S
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65



Just remember that when it comes to JavaScript, it's what's sent to the browser that matters; not the server-side markup.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validate JSP form through JavaScript
 
Similar Threads
validation messages not displaying the error messages in the HTML boxes
dynamic Checkboxe value retrieval
Killing session when closing the browser
struts-2 (set values to action class)
[Struts 2] How to populate select control after selection of a value in another select control