Search code examples
jqueryspring-mvcjquery-ui-multiselect

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


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.


Solution

  • 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