Q: Using multiselect onchnage event to call the action using ajax?

Inside your page:

<script type="text/javascript">
    function search() {
        var countries = $('#countries').val();
        var albums = $('#albums').val();
               $.ajax({
            url:"<%=url_for :controller => 'music_on_demand',:action => 'combined_search' %>",
            data:'country=' + encodeURIComponent(countries) + '&albums=' + encodeURIComponent(albums),
            cache:false,
            success:function (data) {
            }
        })
    }
</script>

……

Inside body :

          <select id="countries" name="country" multiple="multiple" onchange="search()">
            <% @country.each do |c| %>
                <option value="<%= c.id %>"><%= c.name %></option>
            <% end %>
          </select>
          <select id="albums" name="country" multiple="multiple" onchange="search()">
            <% @album.each do |al| %>
                <option value="<%= al.id %>"><%= al.name %></option>
            <% end %>
          </select>

..You can use jquery multiple select for the nice looks. link: http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: