I am trying to implement dynamic select on the in the following code. I have product and product has many batch nos. as soon as i select Product associated Batch no should be displayed. Form details are as follows.
<div class ="prod"><%= f.association :product, :collection => Product.in_stock %> </div><br/>
<div class ="batch"><%= f.grouped_collection_select :batch_no, Product.in_stock, :store_opening_stocks, :title, :batch_no, :batch_no, :prompt => "Select Batch"%></div>
and jquery for the form is as follows
jQuery(document).ready(function(){
var child = jQuery('.batch').html();
jQuery('.prod').change(function() {
var parent = jQuery('.prod :selected').text();
var escaped_parent = parent.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
var options = jQuery(child).filter("optgroup[label='#{escaped_parent}']").html()
if (options) {
jQuery('.batch').html(options);
return jQuery('.batch').parent().show();
} else {
jQuery('.batch').empty();
}
});
});
Now the problem is options is returning null. this i found out when i did alert(options) it is showing null. Can anyone please poitn me to right direction?? is there any other way i can achieve my task. Thanks in advance :)