Fire submit when drop down box item clicked

Allen Walker wrote:

This may not be rails specific, but i have a select drop down box and want the "submit" action fired when the user clicks one of the options in my drop down select tag box. How do I accomplish this?

thanks

Hey,

You need to call Ajax request onChange event of dropdown.

you can follow this steps. 1) add onChange event with select tag. 2) call your responsible action using Ajax request. 3) render update your rhtml.

Hitesh Rawal wrote:

Allen Walker wrote:

This may not be rails specific, but i have a select drop down box and want the "submit" action fired when the user clicks one of the options in my drop down select tag box. How do I accomplish this?

thanks

Hey,

You need to call Ajax request onChange event of dropdown.

you can follow this steps. 1) add onChange event with select tag. 2) call your responsible action using Ajax request. 3) render update your rhtml.

Actually AJAX isn't necessary for this. All the OP asked to do is submit the form. He can do that with by adding something like this to his onchange event of his drop-down list:

onchange="myForm.submit();"

Or even better would be to add an observer to the drop-down or to the form. This is becoming the preferred method because it uses an "unobtrusive JavaScript" approach.

See the Prototype Element.observe for details on how to use observers: http://www.prototypejs.org/api/element/observe

Or jQuery Events if you prefer that: http://docs.jquery.com/Events

Just remember with this approach you need to wait for the DOM to load before adding the observer. See the jQuery ready() method for more information about that. Prototype also has a way to do this, but isn't as elegant as jQuery's ready() method.