I have a bootstrap modal, that is offers users to add or edit bank account data.
When I click "Edit" Btn to edit bank data, the modal will set the value to the input value and select the option.
But in the modal, I have two select options, top of the select is to choose bank code,
and when the select changes, it will trigger change function to use ajax to get branch bank list.
So if I want to set the value to the modal, the top select option (bank) can successfully set value,
but the bottom select option (branch) will not successfully set the value to the modal.
My code is:
// Set top select option
$('#selectBankList option[value=' bankName[0] ']').attr('selected','selected');
// Show Modal
addBankModal.show();
// getBranchList
f_getBranchList(bankName[0]);
$(document).ready(function() {
// Set bottom select option
$('#selectBranchName option[value=' branchName ']').attr('selected','selected');
});
I've to try putting the set #selectBranchName value to anywhere, but still not working.
So, where is my code wrong?
CodePudding user response:
$('#id attribute[foo="bar"]');
you have not added inner quotes
CodePudding user response:
$('#selectBankList ').on('change', function(){
$('#selectBranchName option[value="' $(this).val() '"]').attr('selected', 'selected').addClass('active');
});