I have two radio button named company_status in my #edit-modal which values are active & inactive; when I will click on a edit button , based on the existing status of the company, the radio button will be selected automatically; how can I do that?
$('#EditModel').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var company_name = button.data('company_name') // Extract info from data-* attributes
// If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
var modal = $(this)
modal.find('.modal-body #edited_company_name').val(company_name);
//modal.find('.modal-body #edited_company_staus').val(company_name);
})
// Im assuming company_status will be "active" or "inactive"
var company_status = button.data('company_status');
var active = $('.modal-body [value="active"]'); // active radio button
var inactive = $('.modal-body [value="inactive"]'); // inactive radio button
// if company status is "active", check the radio button that has value of active, uncheck otherwise
if (company_status == 'active') {
active.prop('checked', true);
inactive.prop('checked', false);
} else {
active.prop('checked', false);
inactive.prop('checked', true);
}