Reputation: 2969
I have a drop down menu. By default it allows only one option to select among all. I want to create a checkbox which when checked should change that dropdown menu to allow multiple options to be selected. How can I achieve this?
<select id="test" name="host">
<option value="host1">host1</option>
<option value="host2">host2</option>
.....
.....
</select>
I want this to be changed to following on checkbox being checked.
<select id="test" name="host" multiple="multiple">
<option value="host1">host1</option>
<option value="host2">host2</option>
.....
.....
</select>
Upvotes: 0
Views: 362
Reputation: 11264
You need to use javascript for that..use a library called 'JQuery', it makes it very simple..
$("#checkbox_id").change(function(){
if($(this).is(':checked'))
$("#test").attr('multiple', 'multiple');
});
Edit: for reverting back..
$("#checkbox_test").change(function(){
if($(this).is(':checked'))
$("#test").attr('multiple', 'multiple');
else
$("#test").removeAttr('multiple');
});
Upvotes: 3