3

I have a dropdownlist having id="ddlTitle".

It contains three values as mentioned below
Mr.
Mrs.
Miss

Current selected item is Mr. I want to change the selected text to some other text of dropdownlist when page refresh.

I am using $('#' + ddlTitle + ' :selected').text(Title); where Title can be Mr. or Mrs. or Miss

There is one problem that if I use the above code, I am able to change the selected text but whatever was the selected text before, didn't appear in dropdownlist.

Example : If current selected text is Mr. then after using this code $('#' + ddlTitle + ' :selected').text('Miss'); Current selected text will become Miss but values in dropdownlist becomes as below:

Miss
Mrs.
Miss

Where as previous values were

Mr.
Mrs.
Miss

0

1 Answer 1

4

You have answer in this thread:

How do I select an item by its text value in a dropdown using jQuery?

you can use this code for example:

$("#ddlTitle option").each(function() {
  this.selected = $(this).text() == Title;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.