I am trying to set a select to a specific option. I am creating my select with this code..
$('#drpSortBy').append($("<option></option>").attr("value", 'Application_ID').text('Application'));
$('#drpSortBy').append($("<option></option>").attr("value", 'Approver_ID').text('Approver'));
$('#drpSortBy').append($("<option></option>").attr("value", 'Days_Pending').text('Days Pending'));
$('#drpSortBy').append($("<option></option>").attr("value", 'Originator_ID').text('Originator'));
$('#drpSortBy').append($("<option></option>").attr("value", 'Title').text('Title'));
I am trying to set the select list to a specific option based on value with this code but it doesnt seem to be responding
$('#drpSortBy option').val(userSort.SortFieldName).attr('selected', true);
I have verified that userSort.SortFieldName=’Originator_ID’ for testing purposes
You can use val() to set selected value.
Live Demo