aspose file tools*
The moose likes Struts and the fly likes Accessing the Struts form object in JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Accessing the Struts form object in JavaScript" Watch "Accessing the Struts form object in JavaScript" New topic
Author

Accessing the Struts form object in JavaScript

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 383
I have a Struts form and a Struts submit button. I also am using a third party JavaScript based date combo box with its own validation. I need to pass the form object to the date script so it can render the combo boxes at startup. The problem is, I know how to access a form object in regular html (this.formName), but how do I do it if Struts is controlling the form?

Code...
<html:form action="searchResults.do">

<!--Date--><SCRIPT>fill_select_from(this.SearchForm);year_install_from(this.SearchForm);</script>

<br><html:submit>Search</html:submit>
</html:form>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The important thing to remember is that struts tags are always rendered to regular html tags before they are displayed.

If you wish to write javascript to manipulate a jsp page created with struts custom tags, the best way to do it is to make frequent use of the "view source" function of your browser. In IE, you just right-click the frame you're in and select "view source" from the context menu.

Once you look at the "View Source" output, you will then see the actual html that was redered by your struts tags. You will then know how to write the javascript to access those html controls because you will know how struts has named them.

Merrill


Merrill
Consultant, Sima Solutions
M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 383
That worked, thanks for the insight Merrill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing the Struts form object in JavaScript
 
Similar Threads
Submitting form
how to get value from combo box
Can javascript function set value of a form bean property?
JavaScript Validation in struts
adding Dynamic text boxes using struts