File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing tag fields useing javascript

 
Oren Mizrahi
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i access a field when im using the struts tags from a javascript?

EX: <html:form action="/processCmSearch.do">
<html:select name="cmSearch" property="country">
<html ptionsCollection name="cmSearch" property="countryChoices" />
</html:select>
....

So now, if I have a javascript thats supposed to modify this field when the user changes an option (using onChange=".."), how would I access this country field from the javascript?

(...using standard html the form would have a name but without that I have no clue how to access the form, yet alone the field itself...)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oren, this is the 2nd time I've moved your Struts-related post to the appropriate forum. Please post Struts questions in that forum.
 
Jay Haley
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go ahead and use name like you normaly do. When your html is built the value of property will be the same as name. If that's not clear view source once you page has been built.
 
Oren Mizrahi
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks jay

but i dont really understand that answer. I cant add "name" to the <html:form> tag. so are u saying i use the property vale of the object im looking to manipulate?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oren,
You can't put "name" in the html:form tag because the form already has a name. It is defined in your struts config file. You can also verify the name by looking at the html code generated by your jsp in a browser.
 
Jay Haley
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need to find out the form name, view source once the page has been built. However, you don't need to use the form name. If you have only one form on your page you can get to it by using "forms[0]". If you have multiple forms just change the "0" to what ever element you need.

I have added an example to explain what I said earlier.
<html:text property="apple"> will build <input type="text" name="apple">
 
Oren Mizrahi
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys,
Thank you very much for your help. i appreciate it. what u guys said worked great!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic