How to get the value of a select's option by its text

marky

I have a dropdown similar to the following:

<select type="select" id="ddl">
    <option value="0">Select...</option>
    <option value="1">Blue</option>
    <option value="2">Red</option>
    <option value="3">Green</option>
    <option value="4">Yellow</option>
</select>

I need to get the value of an option when I have the text, independent of whether anything is selected or not.

I tried $('#ddl[text=Blue]).value(), but that wouldn't work. I don't know what else to try.

Thanks.

SELECT EXAMPLE FIXED (I copy/pasted the wrong line - sheesh! ;) )

Gone Coding

JSFiddle: http://jsfiddle.net/thfg5/2/

var color = "Red";
alert($('#ddl option:contains("' + color + '")').attr("value"));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AngularJS + Protractor How to select Dropdown option based on its text not value

From Dev

Select Dropdown option based on its text not value

From Dev

How I get the text instead value from a select option in CodeIgniter

From Dev

How can I hide an option of a select by it's text value?

From Dev

How to get the text of a single option using it's value with BeautifulSoup

From Dev

use jQuery to select option from menu based on its text not value

From Dev

Get value of HTML select option using its index with jQuery

From Dev

How to get option value of select element

From Dev

How to get the option value of selected in Select dropdown

From Dev

Select the next select box beside a td and then select an option by its text value

From Dev

How do I get the text and not the value of an Option?

From Dev

How to get Select option dropdown text value using reactive form in Angular

From Dev

How to update select text with matched option value text

From Dev

Form select option, can't get the value and display text right

From Dev

How to get the specific option value of a dropdown by passing the option text in jquery

From Dev

How to get an option element's value by name

From Dev

How to get values from the xml value without mentioning its attribute's name in select statement

From Dev

Find select option value by text

From Dev

jquery click select option value with option text

From Dev

How to Exchange Value Between Select Option and Text Input On Conditional

From Dev

How to change text inside 'value' attribute of option(select)?

From Dev

How can disable an option select if its text is equal to another text in a div?

From Dev

Select option does not get the value

From Dev

Select option,get the option value before submit

From Dev

how to get the value of option values on select change in jquery

From Dev

Angular 2 - how to get value from select / option

From Dev

How to get value of select option an used in php variable?

From Dev

How to get specific value from option select - json object

From Dev

How to get the selected option value from select inside div

Related Related

  1. 1

    AngularJS + Protractor How to select Dropdown option based on its text not value

  2. 2

    Select Dropdown option based on its text not value

  3. 3

    How I get the text instead value from a select option in CodeIgniter

  4. 4

    How can I hide an option of a select by it's text value?

  5. 5

    How to get the text of a single option using it's value with BeautifulSoup

  6. 6

    use jQuery to select option from menu based on its text not value

  7. 7

    Get value of HTML select option using its index with jQuery

  8. 8

    How to get option value of select element

  9. 9

    How to get the option value of selected in Select dropdown

  10. 10

    Select the next select box beside a td and then select an option by its text value

  11. 11

    How do I get the text and not the value of an Option?

  12. 12

    How to get Select option dropdown text value using reactive form in Angular

  13. 13

    How to update select text with matched option value text

  14. 14

    Form select option, can't get the value and display text right

  15. 15

    How to get the specific option value of a dropdown by passing the option text in jquery

  16. 16

    How to get an option element's value by name

  17. 17

    How to get values from the xml value without mentioning its attribute's name in select statement

  18. 18

    Find select option value by text

  19. 19

    jquery click select option value with option text

  20. 20

    How to Exchange Value Between Select Option and Text Input On Conditional

  21. 21

    How to change text inside 'value' attribute of option(select)?

  22. 22

    How can disable an option select if its text is equal to another text in a div?

  23. 23

    Select option does not get the value

  24. 24

    Select option,get the option value before submit

  25. 25

    how to get the value of option values on select change in jquery

  26. 26

    Angular 2 - how to get value from select / option

  27. 27

    How to get value of select option an used in php variable?

  28. 28

    How to get specific value from option select - json object

  29. 29

    How to get the selected option value from select inside div

HotTag

Archive