Reputation: 3378
I'm trying to select a particular option based on what I get from a query;
$('#Adjunct_Title_Number > option[value=' + response.Adjunct_Title_Number + ']').attr('selected','selected');
I simply get nothing selected. I know that the value of 58 is being inserted into the statement.
Upvotes: 1
Views: 66
Reputation: 12577
First of all check if $('#Adjunct_Title_Number > option[value=' + response.Adjunct_Title_Number + ']')
is a defined item (not empty object).
Next you should on older jQuery to remove attribute selected from other items:
$('#Adjunct_Title_Number option').removeAttr('selected').filter(function(){
return ($(this).value == response.Adjunct_Title_Number) })
.attr('selected','selected');
Upvotes: 0
Reputation: 4529
Try surrounding the value with quotes:
$('#Adjunct_Title_Number > option[value="' + response.Adjunct_Title_Number + '"]').attr('selected','selected');
Upvotes: 0
Reputation: 8457
$('#Adjunct_Title_Number option').filter(function() {
return this.value == response.Adjunct_Title_Number;
}).prop('selected','true');
Upvotes: 0
Reputation: 30135
You don't set a select box by setting selected
on the options, but by setting the value of the select box with val()
:
$('#Adjunct_Title_Number').val(response.Adjunct_Title_Number);
Upvotes: 1
Reputation: 27012
Try this instead:
$('#Adjunct_Title_Number').val(response.Adjunct_Title_Number);
Upvotes: 1