Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery UI Combobox ONCHANGE

how can I attach an onchange function in a jqueryUI combobox? Here is my code:

$(".cmbBox").combobox({      change:function(){          alert($(this).val());      } }); 

When the value changes, it will alert the updated value.

Any help please.. :)

like image 730
Vincent Dagpin Avatar asked Jan 21 '11 15:01

Vincent Dagpin


1 Answers

The combobox example source is all right there in the example. I'd trigger the change event of the underlying select by modifying the source code like this (changing the select event handler inside autocomplete initialization inside the plugin):

/* Snip */ select: function( event, ui ) {     ui.item.option.selected = true;     self._trigger( "selected", event, {         item: ui.item.option     });     select.trigger("change");                             }, /* Snip */ 

and then define an event handler for the regular change event of the select:

$(".cmbBox").change(function() {     alert(this.value); }); 

Unfortunately this won't work exactly the same way as the normal select.change event: it will trigger even you select the same item from the combobox.

Try it out here: http://jsfiddle.net/andrewwhitaker/hAM9H/

like image 115
Andrew Whitaker Avatar answered Sep 17 '22 14:09

Andrew Whitaker