onclick on assign to rm button , i want to get on rm names listed as a dropdown Any help is appreciatable.
mynview, gu_rent_property_list.html.erb
<% @properties.each do |property| %> <%= link_to "Assign To Rm", {:class=>"btn btn-danger",:onclick => 'update_subscategories_div(<%=property.category_id %>.value)'%>} %> <div class="col-md-6 resp_dropdown"> <div class="wrapper-demo wrapper-demo_left wrapper-demo_rightforjs"> <select class=" wrapper-dropdown-3_1 wrapper-dropdown-3_1forjs" id="categoriesDiv" name="property[rm_id]"> </select>​ </div> </div>
my javascript code is this
function update_subscategories_div(category_id) {
// alert(category_id);
var result = {}, objectlength, select_options = ''
if (category_id == '') {
jQuery('#categoriesDiv').html('');
} else {
jQuery.ajax({
url: "assign_rm/" + category_id + ".json",
type: "GET",
data: {"category_id": category_id},
dataType: "html",
success: function (data) {
result = JSON.parse(data)
objectlength = result.length
for (var i = 0; i < objectlength; i++) {
select_options += '<option value=' + result[i].id + '>' + result[i].name + '</option>'
}
jQuery('#categoriesDiv').html(select_options);
}
});
}
}
controller
def gu_rent_property_list @properties =Property.where(id: params[:id]) end
Aucun commentaire:
Enregistrer un commentaire