After appending a select option and selecting the appended option alert shows undefined + Jquery -
i newbie jquery , trying append select option. works , when select newly added option in select. getting undefined in alert.
var selects = $(this).closest('div').find('.accselectandlookup') ; //check if accid present in selectoptions , if not add if (!selects.find('option[value="' + accid + '"]').length) { alert(accid); // throws correct value selects.append('<option value="' + accid + '">attach existing : ' + accname + '</option>'); }
what doing wrong ?
thanks in advance
selects.change(function(){ alert('selected value ' + selects.filter(":selected").val()); // throws undefined })
simply use $(this).val(
) selected option
value of current select
. selects
might not available when change
event fired due variable scope.
selects.change(function(){ alert('selected value ' + $(this).val()); // throws undefined });
Comments
Post a Comment