0

I've got a combo box with options, what I want is a function where I send one of the options, and the combo box set that option to the selected one, showing it.

I try

$("#cmbStrategies option:selected").html('Condor');

It works set Condor as the selected option, but adding it has a new option, resulting in two option Condor.

I want just select the option but not adding a new one.

2

3 Answers 3

0

I think you may want to use .val('Condor') not .html().

Sign up to request clarification or add additional context in comments.

Comments

0
$("#cmbStrategies").val('Condor'); should do the trick.

$("#cmbStrategies option:selected").html('Condor');

This jQuery selector is um "wonky".

4 Comments

$("#cmbStrategies").val('Condor'); Dosen't set the selected text of the combo box to 'Condor'. $("#cmbStrategies option:selected").html('Condor');
@DiegoUnanue It will if you have an <option value="Condor">Condor</option>, if you have a different value for `Condor', then use it's value
$("#cmbStrategies option:selected").html('Condor'); works I can see the selected option as 'condor' but duplicates the option. Resulting in two options 'Condor'
@DiegoUnanue Why are you adding in the option:selected use jQuery sector of the select box, and set it's value. With the selector you used above, you are pointing in another area, plus you have gone back to html.
0

This worked for me:

$("#myDropDown option:contains(myText)").attr('selected', true);

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.