function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
James Allen 4James Allen 4 

JQuery Muliselect by Eric Hynds trouble pre-selecting Options. 

I have implemented the multiselect JQuery tool on a visualforce page to select users from a list.  I am now expanding the functionality to include more users using the OptGroup feature and I would like to pre-select user belonging to the default group.

However when building the standard <select multiple="multiple" > list I can't find a way to only select certain <option>.  It appears that the Jquery conversion to the checkbox UI only looks for selected.  So no matter if you add selected="true" or selected="false" it still checks all the check boxes.

I am trying to find a way to either manipulate the <select> or use Jquery/javascript to update the control to pre-select certain options.

Here is my VF code.  I can include the Multiselect script as well if that helps.  

                   <select id="selectCoaches" style="display:none" multiple="multiple" >  
                      <apex:repeat value="{!GroupNames}" var="group">  
                            <optgroup label="{!group[0]}">
                             <option value="{!group[1]}" selected="{!group[2]}">{!group[1]} </option>  
                            </optgroup>
                      </apex:repeat>  
                   </select>  

If I set selected="" it does not check the box but I can't conditionaly set it to a blank value. 

I have read posts about using .val() to set it via JQuery but my javascript skills are still developing and I am not sure where or how I would set it based on values coming from the controller. 

Thanks for any help!