javascript - JQueryUI autocomplete doesn't update its data-attribute from the select box -


example

$('select').change(function(){       $('#auto').attr('data-id',$(this).val()) })  $('#auto').autocomplete({     delay: 1000,     source: function( request, response ) {               alert($(this.element).data('id'))             return false     }  })  <select name="category">     <option value="a">a</option>     <option value="b">b</option>     <option value="c">c</option> </select>  <input id="auto" data-id="a" type="search"/> 

i want update auto-input data attribute when select option in selectbox.

is there way prevent auto-complete input caching data attribute? input able update data-id first time change option b in selectbox. when change b c, input still alerting b instead of c. $(this.element).data('id') not appropriate way of getting latest data attribute?

what picking value directly select control, this:

$('#auto').autocomplete({     delay: 100,    source: function( request, response ) {         var selected = $('select[name="category"] option:selected'),            issomethingselected = selected.length == 1,           selectedval = issomethingselected ?                          selected.val() :                           $('select[name="category"] option:first').val();       alert(selectedval);       return false;    } }); 

see jsfiddle


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -