Jquery set selected option based on text

By: obogrel007 Date: 17.06.2017

jQuery set dropdown option based on text | [H]ard|Forum

In the above dropdown i know the text of the dropdown. How can set the value of the dropdown in document.

jquery set selected option based on text

This is a method that works based on the text of the option, not the index. Sign up for our newsletter and get our top new questions delivered to your inbox see an example. By posting your answer, you agree to the privacy policy and terms of service.

Stack Overflow Questions Developer Jobs Documentation beta Tags Users.

Sign up or log in to customize your list. Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us.

Populate Dropdown on the basis of another dropdown value in PHP using JQuery Ajax

Log In Sign Up. Join the Stack Overflow Community. Stack Overflow is a community of 7. Join them; it only takes a minute: I have a dropdown as: Peter J 43k 7 30 To handle the similar values prolem you can get the first match with the index [0] the default returns the last index like this: The above methods are broken in jquery from version 1.

Your fiddle works for me. If it isn't multiple select, break each loop with return false from anonymous function. Did you find this question interesting?

jquery set selected option based on text

Try our newsletter Sign up for our newsletter and get our top new questions delivered to your inbox see an example. Please click the link in the confirmation email to activate your subscription.

Parham 8 Vinay saini 49 1.

javascript - change dropdown selected value based on textbox value in jquery - Stack Overflow

Matthew Feerick 11 1. The below code works for me -: BalusC k Maybe because that only works if your option value is the same as the text. So in the OP's example, the GOOGLE text option has a value of 2 so it does not work. Here is an simple example: This is worked both chrome and firefox set value in to dropdown box.

jquery - Set select option 'selected', by value - Stack Overflow

Naveenbos 1, 2 22 How can i get the index of the text? This doesn't answer the question.

The OP wants to set the selection based on the text, not the index. Sign up or log in StackExchange. Sign up using Facebook.

Sign up using Email and Password. Post as a guest Name. Stack Overflow works best with JavaScript enabled. Think this only works with the index not the text.

Cheers S share improve this answer. MathOverflow Mathematics Cross Validated stats Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy more 3. Meta Stack Exchange Stack Apps Area 51 Stack Overflow Talent.

inserted by FC2 system