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

--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to