This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validate JSP form through JavaScript

 
Samuel Castillo Romero
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Samuel Castillo Romero
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic