Reputation: 325
how can I select multiple value in this country dropdown
this is my code:
function print_country(country_id) {
// given the id of the <select> tag as function argument, it inserts <option> tags
var option_str = document.getElementById(country_id);
option_str.length = 0;
option_str.options[0] = new Option('Select Country', '');
option_str.selectedIndex = 0;
for (var i = 0; i < country_arr.length; i++) {
option_str.options[option_str.length] = new Option(country_arr[i], country_arr[i]);
}
}
Upvotes: 0
Views: 5753
Reputation: 484
Use the option.selected property like this:
var option_str = document.getElementById('country_id');
for ( var i = 0; i < option_str.options.length; i++ )
{
if ( //condition for selecting the current option)
{
option_str.options[i].selected = true;
}
}
Upvotes: 1
Reputation: 114
<select class="form-control select2 color-gray" multiple="multiple">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<option>Option 4</option>
<option>Option 5</option>
</select>
Jquery
$(".select2").select2();
you can download select2 plugin on github. link mention on below. https://github.com/select2/select2/tree/develop/dist/js
Upvotes: 0