Inspite of change event trigger the modal on click event of select option like
$('select option').on('click',function(){
$("#modelId").modal('show');
});
Create a select with a default value option.
<select id="slt">
<option value="default">Select Something</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Every time, handle the change event for a not defaultValue option, and then reset the default option to selected.
var $slt = $('#slt'),
defaultValue = 'default';
function handleChange(e){
var val = $slt.val();
// do nothing for defaultValue being selected
if (val === defaultValue) {
return;
}
// do something else
console.log(val);
// reset the value to defaultValue
$slt.find('option:selected').prop('selected', false);
$lst.find('option').eq(0).prop('selected', true);
}
$slt.bind('change', handleChange);
But this will make the select always show as "Select Something".
This is a demo about this: http://codepen.io/shuizhongyueming/pen/JWYYLJ
I found another solution for this, which is better than mine.
https://stackoverflow.com/a/12404521/2279763
It use the selectedIndex to reset the selected value on focus, no need for the defaultValue option, and will show the the selected option after click.
This is the demo in the comment: http://fiddle.jshell.net/ecmanaut/335XK/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With