Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Validate JSP form through JavaScript

 
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
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.

 
New rule: no elephants at the chess tournament. Tiny ads are still okay.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic