After changing a menu from a regular select to a jQuery selectmenu, I can no longer select options in it programatically. Is there a way to do this?
The code to select is (assuming ListId is the actual Id of the list)
$('#ListId').val(value);
The plugin is activited like this:
$("#ListId").selectmenu({ style: "dropdown", width:140 });
Is there a way to select an item in the select menu? Calling the same .val(value) function just selects the value in the hidden original select list, not the nicely styled jQuery selectmenu.
You could additionally trigger the change event handler by adding a change call:
I have tried the following ways, and it does work in my situation
OR
Assuming that you have already done this part once before:
I found this works:
This causes the the stylized drop down to show the correct value.
I have tried the following, and it does not work in my situation
1.
2.
3.
refresh, selected ....etc. and in some situation it does not work.
Therefore, I press ctrl+I in chrome to see the source code. and I use the following code to solve my situation.
Please note you must use indexes (not values) to select the option using this method.
For instance, given this select.
In this case the expression
$('#ListId').selectmenu("value", "value-two");
wouldn't return any result. Instead of that, we have to use$('#ListId').selectmenu("value", "2");
. In other words, we have to use the position/index of the element inside the select. Not the value!Finding the index is easy though. You can use the following line to achieve it.