How to Pass Jquery selected dropdown values and radio button values to controller

146 views
Skip to first unread message

mugdha r.

unread,
Jun 18, 2013, 2:28:57 PM6/18/13
to rubyonra...@googlegroups.com
Hi,

I have an advance search page and its code is as follows -

I have written my code like this
<div class="container">
<%= form_tag search_index_path, method: :get do %>
<%= radio_button_tag 'user_type', 'customer' %><p>Customer</p>
<%= radio_button_tag 'user_type', 'supplier' %><p>Supplier</p>
<% end %>
<h2>Search Criteria</h2>
<div id="dropdown">
<p>State</p>
<%= collection_select(:customer, :customer_number, Customer.all,
:id, :state) %>
<p>City</p>
<%= collection_select(:customer, :customer_number, Customer.all,
:id, :city) %>
<p>Name</p>
<%= collection_select(:customer, :customer_number, Customer.all,
:id, :name) %>
</div>
<div id="dropdown1">
<p>State</p>
<%= collection_select(:supplier, :supplier_number, Supplier.all,
:id, :state) %>
<p>City</p>
<%= collection_select(:supplier, :supplier_number, Supplier.all,
:id, :city) %>
<p>Name</p>
<%= collection_select(:supplier, :supplier_number, Supplier.all,
:id, :name) %>
</div>
</div>

<%= submit_tag "Search", name: nil %>
<script>
$(document).ready(function() {
$("#dropdown").hide();
$("#dropdown1").hide();
$("input[type='radio'][name='user_type'][value='customer']").click(function(){
$("#dropdown1").hide();
$("#dropdown").show();
$("input[type='radio'][name='user_type'][value='supplier']").click(function(){
$("#dropdown").hide();
$("#dropdown1").show();

});
});
});
</script>

I have two models and controllers for customer and supplier
respectively. Now after selecting the values on search page when user
click on search how to pass these values to controller so that it will
return search results from model.

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

Rafal Stepien

unread,
Jun 19, 2013, 10:01:18 AM6/19/13
to rubyonra...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c44fcfe02abd942232f06e9bc28ae133%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.



Reply all
Reply to author
Forward
0 new messages