Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validate JSP form through JavaScript

 
Samuel Castillo Romero
Greenhorn
Posts: 26
  • 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: 64822
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 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
  • 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: 64822
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic