$('#item_code_wrapper').on('keyup blur', '#item_code', function(){
if( $(this).val() != ""){
$.ajax({
url : "../item/code/" + $(this).val(),
success: function(data){
if (data.success == 'false') {
$('#item_description option').removeAttr('selected');
}else{
$('#item_description option:eq(' + data.item_id + ')').attr('selected', true);
}
}
});
}
});
This one works if I copy and paste the code. It points to the option with the item id and it also remove the selected if data success is false. But then again, If I manually type item code and has a matching id it changes the option to selected but it doesn't point to that particular option.