Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select an option in a jQuery ui selectmenu dynamically?

Tags:

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.

like image 692
Jamie Avatar asked Dec 14 '10 22:12

Jamie


2 Answers

Assuming that you have already done this part once before:

$("#ListId").selectmenu({ style: "dropdown", width:140 });

I found this works:

$('#ListId').val(value);
$('#ListId').selectmenu("refresh");

This causes the the stylized drop down to show the correct value.

like image 39
Coder_X Avatar answered Oct 12 '22 01:10

Coder_X


$('#ListId').selectmenu("value", value);
like image 166
Brandon Joyce Avatar answered Oct 12 '22 01:10

Brandon Joyce