1

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.

2
  • Is this script located in a separate file? Commented Aug 5, 2013 at 20:43
  • Separate from what? It's inline script. Commented Aug 5, 2013 at 20:53

5 Answers 5

1

Try this instead:

$('#Adjunct_Title_Number').val(response.Adjunct_Title_Number); 
Sign up to request clarification or add additional context in comments.

Comments

1

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); 

Comments

0
$('#Adjunct_Title_Number option').filter(function() { return this.value == response.Adjunct_Title_Number; }).prop('selected','true'); 

Comments

0

Try surrounding the value with quotes:

$('#Adjunct_Title_Number > option[value="' + response.Adjunct_Title_Number + '"]').attr('selected','selected'); 

Comments

0

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'); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.