JQuery Select few option of multi-select on click of another checkbox

964 views Asked by At

I want to select few values of the multiple select box options on click of another checkbox using jquery. This select box uses multiselect filter plugin.

<h3 class="accordion_head">
            <a href="#">Company Region</a><span class="bg arrow"></span>
        </h3>
        <div class="accordion_body">
            <ul>    
                <li><input id="companyRegion1" name="companyRegion" value="GCC" type="checkbox">
                    <label for="companyRegion1">GCC</label></li>
            </ul>
        </div>

And the second select box I follows spring tag as below

<form:select path="${elementPath }" multiple="multiple" cssClass="multi_select">
    <form:options items="${valueList}" itemLabel="${label}" itemValue="${itemVal }" />
</form:select>

So when clicking on the checkbox mentioned above I need to preselect GCC countries in the multiple select box. this is implemeted using multiselect jquery plugin

I have tried this way but it is not getting selected.

$('#companyCountries option[value=247]').prop('selected',true);

Please help.

2

There are 2 answers

0
Shams On BEST ANSWER

I solved by calling the refresh as mentioned in the multi-select plugin site. I couldn't invoke by form name, so removed form name.

$("#companyCountries").multiselect('refresh');

Thanks for the responses

0
Vijay On

The Code for checking the check box is as below for JQuery 1.6 and above. The JQuery versions below you have check with api documentation $.prop()

`$('#CompaniesSearchForm countries option[value=247]').prob('checked',true);`