I have a problem with select menu on my html page (bootstrap, jquery, js). On my requirement, the select menu (see the pictures below) should, at the first time show only 1,2,3
and others and if the user chooses "others"
a sub menu should appeare on the same select menu allowing the user to choose 4
and 5
options without hiding the old menu.
I tried to do it with some Jquery code (by appending the 4
and 5
options when the user clicks on other option) the problem is the select is closed when I choose the other option.
<select name="mySelect">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="others">Others</option>
</select>
$(function(){
$('select[name=mySelect]').on('change', function(){
var selected = $(this).val();
if(selected && selected == 'others'){
$(this).children().last().remove();
$(this).append('<option value="4">4</option><option value="5">5</option>');
$(this).click();
}
});
});
How to disable the select closing
when the user clicks on "Other"
option?