Forum: Ruby on Rails unable to observe select_tag's value

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8d295740bdc6fecc406cff2e8b895f48?d=identicon&s=25 Sahil Dave (Guest)
on 2009-03-16 07:09
(Received via mailing list)
Hi,

I am trying to observe a select_tag's value, and insert a partial inside
the
page based on that value. Here's the code:

#index.html.erb
<% form_tag do %>
  <%= select_tag 'product_id',
options_from_collection_for_select(@products, 'id', 'pro_name'), {:id
=> 'product_id'} %>
  <%= select_tag 'taxation_id',
options_from_collection_for_select(@taxations, 'id', 'tax_name'), {:id
=> 'taxation_id'} %>
  <%= observe_field 'product_id', :url => {:controller =>
'regulations', :action => 'show'}, :with => "'id=' + value" %>
<% end %>

<div id="regulations">
</div>


#regulations_controller.rb
def show
    @regulation = Regulation.find_by_product_id params[:id]

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @regulation }
      format.js
    end
end


#show.js.rjs
page.alert("you are here!")
page.insert_html :bottom, 'regulations', :partial => 'all', :locals =>
{ :regs => @regulations }

Index.html looks like this:

<form action="/regulations" method="post"><div
style="margin:0;padding:0"><input name="authenticity_token"
type="hidden" value="c805ed772e50e2f5b51f8bb92a1387a3dda280b3"
/></div>
  <select id="product_id" name="product_id"><option
value="1">joomla</option></select>
  <select id="taxation_id" name="taxation_id"><option
value="1">VAT</option></select>

  <script type="text/javascript">
//<![CDATA[
new Form.Element.EventObserver('product_id', function(element, value)
{new Ajax.Request('/regulations/show', {asynchronous:true,
evalScripts:true, parameters:'id=' + value + '&authenticity_token=' +
encodeURIComponent('c805ed772e50e2f5b51f8bb92a1387a3dda280b3')})})
//]]>
</script>
</form>

Is something missing or wrong in the above code? even the alert is not
getting called.

Regards

--
Sahil
This topic is locked and can not be replied to.