javascript - Binding onChange on ajax return -
i replacing select on ajax callback. in drop down see returned list, when try bind change event, gives me incorrect value. alert shows me "value undefined", how see correct value when change selected option in drop down list?
if dropdown has values ("value1","value2","value3") , if select "value1", alert should show me "value value1".
if (status == "success") { var mysel = $('#namelist').empty(); (var = 0; < data.length; i++) { mysel.append('<option value="' + data[i] + '">' + data[i] + '</option>'); } $("#namelist").replacewith(mysel); $('#namelist').bind('change', function () { alert('value change ' + $(this).attr('value')); }); }
you should try getting val() instead of attr('value'):
$('#namelist').bind('change', function () { alert('value change ' + $(this).val()); });
Comments
Post a Comment