This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html:options onclick

 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic