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:

<script type="text/javascript">
$('sku_name').observe('click', function(event){
  alert(Event.element(event).innerHTML);
 });
                                                                                
                          </script>


Robert Walker wrote:
> 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.

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to