How can I add or remove options in JQuery UI Multiselect ? I am initializing the multiselect on page load and I need to remove existing values and add new values based on anothe
Here is what I did:; it may be more than necessary, but it worked for me.
Original "select" code that requires modification:
I rebuild the option list in PHP, send it to the JavaScript via JSON, and construct/store the new list in a variable. E.g.:
// this is similar to if we got it from PHP
var newList = '
';
Now, to switch this around in the jQuery UI Multiselect widget:
$('#MySelect').html(''); // clear out old list
$('#MySelect').multiselect('destroy'); // tell widget to clear itself
$('#MySelect').html(newList); // add in the new list
$('#MySelect').multiselect(); // re-initialize the widget
In particular, I re-initialized it with parameters, e.g.:
$('#MySelect').multiselect({selectedList: 4, header: false});
If anybody has read this far down and is still having troubles, give this a try.