• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

html:options onclick

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic