aspose file tools*
The moose likes Struts and the fly likes accessing tag fields useing javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "accessing tag fields useing javascript" Watch "accessing tag fields useing javascript" New topic
Author

accessing tag fields useing javascript

Oren Mizrahi
Greenhorn

Joined: Jun 30, 2004
Posts: 11
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

Joined: Jan 10, 2002
Posts: 61610
    
  67

Oren, this is the 2nd time I've moved your Struts-related post to the appropriate forum. Please post Struts questions in that forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jay Haley
Greenhorn

Joined: May 18, 2004
Posts: 9
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

Joined: Jun 30, 2004
Posts: 11
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

Joined: May 26, 2003
Posts: 30917
    
158

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

Joined: May 18, 2004
Posts: 9
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

Joined: Jun 30, 2004
Posts: 11
hey guys,
Thank you very much for your help. i appreciate it. what u guys said worked great!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: accessing tag fields useing javascript