Fire submit when drop down box item clicked


#1

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


#2

Allen W. 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.

#3

Hitesh R. wrote:

Allen W. 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.


#4

So let’s say I have:

<% form_for :skus do |f|%>
Product: <%= f.text_field :name, :autocomplete => “off”, %>
<%= submit_tag “Get Product” %>
<% end -%>

then how should I do the prototype observe code? I tried and no alert
fired:

Robert W. wrote:

Hitesh R. wrote:

Allen W. 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.