File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes html:options onclick Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:options onclick" Watch "html:options onclick" New topic
Author

html:options onclick

Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Hello
I am using the html ptions tag with a prepopulated collection and jstl; it works quite well. However I have to click the submit button to fire the action. Is there a way to have the selection from the select dropdown to automatically fire the action? I know the javascript events are elements of the tag, but I dont know how to make the event in the options or select fire the submit button. tia.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
It's quite easy, actually

<html:select property="myProperty" onchange="this.form.submit()" />

The onchange event is better for this than onclick. You don't want to submit the form when you click on it: only when you change the value.


Merrill
Consultant, Sima Solutions
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Originally posted by Merrill Higginson:
It's quite easy, actually

<html:select property="myProperty" onchange="this.form.submit()" />

The onchange event is better for this than onclick. You don't want to submit the form when you click on it: only when you change the value.


Hi
Thanks. Is there a way to hiding the submit button, but still having it genereate a key/value when submitted by the onchange event?
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Originally posted by Chris Pat:


Hi
Thanks. Is there a way to hiding the submit button, but still having it genereate a key/value when submitted by the onchange event?


Hi
Actually I just tried this and it didnt work, ideas? It works, but I still have to click submit. tia.

<html:select property="lecturer" onchange="this.form.submit()">
<option value="All">All</option>
<html ptions collection="dropDown" property="name" labelProperty="name" />
</html:select>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Do you have an <html:submit> tag with a property name of "submit" on the same page? If so, this will cause the above code to not work. Just change the name to "save" or something else. You might also check to see that JavaScript is turned on in your browser.

Also, regarding your other question about making this work with a lookupDispatach action, it's a little more complicated, but it can be done: Just remove the submit button and create a hidden field with the same property name that your submit button had like this:

<html:hidden property="save" />

Once again: the property name cannot be "submit"

put the following code in the <head></head> block of the html.

<script> var submitName = '<bean:message key="label.submit" />';</script>

Then modify the onchange code to: onchange="document.forms[0].save = submitName;this.form.submit()"

This is assuming that label.submit was the value used by your old submit button.
[ April 29, 2006: Message edited by: Merrill Higginson ]
 
Don't get me started about those stupid light bulbs.
 
subject: html:options onclick
 
Similar Threads
submit button
JSP + struts html:select
how to populate a list in a another select tag using a select tag using struts 2 & DOJO (ajax)
to pass variable to servlet from html
JSP + struts html:select