JQM multiselect list option Set value selected from database

265 Views Asked by At

I have created and multi-select list option I am able to store the values of the data which are selected and store those value in database know what I want to do is set the multi select option selected as per the values stored in the data base. Here is the code of creating and multi select option:

<select name="select-choice-b" id="select-choice-b" class="validate[required]" data-native-menu="false"data-theme="c" multiple>
                    <option value="">Choose Source</option>
                    <option value="No Source">No Source</option>
                    <option value="Our Website">Our Website</option>
                    <option value="Word of mouth">Word of mouth</option>
                    <option value="Referral">Referral</option>
                    <option value="Newspaper Ad">Newspaper Ad</option>
                    </select>

here is the javascript to set the option selected base on values: here resource contains values:No Source,Our Website

var optionvalue=item['resource'];
                            var values=optionvalue.split(",");
                            $("#"+element_Id).filter('[value='"+values+"']')attr('selected','selected');
1

There are 1 best solutions below

0
On

you need to refresh your select element when selecting options programatically.

Run the following after your script

$('#select-choice-b').selectmenu('refresh');

More info here: (http://jquerymobile.com/demos/1.2.0/docs/forms/selects/methods.html)