javascript - jQuery dropdown select event -
is there specific event when user selects item in dropdown box? creating large form uses multiple dropdown boxes. on load first disabled, user selects first option options in second box change using ajax , want remove attribute disabled.
$('#site_id').on('change', function(event) { $('#access_type_id').removeattr('disabled'); });
the trouble having .change()
seems fired when options in dropdown change making following dropdown boxes enabled before want them be. there alternative event can use in place of change "enable" form field once user has made selection in previous dropdown?
update
i managed solve not using change event @ , placing removeattr in success section of ajax call. example below. allowed me make "next" dropdown enabled @ time populating options.
$('#access_speed_id').on('select2-blur', function(event){ $.ajax({ async: true, data: $('#access_speed_id').serialize(), datatype: 'html', success: function(data, textstatus) { $('#cdr_id').removeattr('disabled'); $('#cdr_id').html(data); }, type: 'post', url: '/services/specificcdrs' }); });
try below code:
<select id="drop1"> <option value="volvo">volvo</option> <option value="saab">saab</option> <option value="mercedes">mercedes</option> <option value="audi">audi</option> </select> <select id="drop2"></select>
jquery
$(document).ready(function(){ $("#drop2").attr("disabled", true); $("#drop1").change(function(){ $("#drop2").attr("disabled", false); //put ajax code here , bind below code $("#drop2").append(new option("option text", "value")); $("#drop2").append(new option("xxx","1")); }); });
Comments
Post a Comment