ajax and rails script for populating dropdown list values based on selected radio button on rails 3
anyone knows what will be the possible ajax and rails script for populating dropdown list values based on selected radio button on rails 3 example there are two type of platform choices(windows, unix) of radio button then when you clicked the unix radio button, the dropdown listbox will filter only the unix type something(patch).
The idea is the dropdown has a开发者_高级运维 contents already from the database (<%= f.select :other_platform, Patch.all.map {|p| ["#{p.patch_type} #{p.number}: #{p.summary}", p.id ] }, {:include_blank => true} %>) then I need to do is to "filter" only the values that has a windows type example base on the radio button that has been selected if you clicked the windows type then the dropdown menu will show only the windows type of patches and hide the unix type or the list that has a unix word on it like regx(checking the query)and if you choose or clicked the unix then only the unix type will appear at the dropdown menu
thanks please answer
imon
I have a codes here: these are the radio button :
what should I do to the ajax codes and to this selectbox? what are the right codes for the ajax and some addition codes for the radio button and to this selectbox.??
true} %>your answers and examples are really appreciated..
thanks, imon
This is quite simple. When user click on the radio button then an ajax request should invoke. You can pass your parameters for taking drop down list from server in the Ajax URL. Then respond the required drop down from server, receive response in Ajax call, populate the dom element. Do it and ask in case of any query.
Edit:
Following is skeleton of your code.
Suppose you have three radio buttons: > input type="radio" name="rdio" value="a" checked="checked" /> > input type="radio" name="rdio" value="b" /> > input type="radio" name="rdio" value="c" /> > div id="drop_down" /> Bind click event like this: $("input[@name='rdio']").click(function(){ var url = '/get_drop_down_options?radio_val=' + $(this).val() $("#drop_down").removeOption(/./) $.get(url, function(data) { $('#drop_down').addOption(data, false); }); }); In your controller, def get_drop_down_options val = params[:radio_val] options = YourModel.collect{|x| "'#{x.id}' : '#{x.label}'"} render :text => "{#{options.join(",")}}" end Now you dont need partial.
精彩评论