progNewbie progNewbie - 3 months ago 47x
jQuery Question

How to trigger 'select' event in jQuery UI Selectmenu

I got this selectmenu:

$( "#software" ).selectmenu({
width : 'auto',
select: function( event, ui ) {
//my code

And I want to programmatically change the selected Item and trigger the 'select' state.

I do the following:

$( "#software" ).val( 1 ).selectmenu( "refresh" ).trigger( "select" );

The selectmenu picks the right option and refreshes it but it doesn't trigger the 'select' state. How can I do this?


You can simply do:-

$( "#software" ).val(1).selectmenu("refresh").trigger("selectmenuselect");

You will need to bind an event listener to the selectmenuselect event like:

$( "#software" ).on( "selectmenuselect", function( event, ui ) {
     alert('New Item Selected!')

Info: select( event, ui )