user3105512
user3105512

Reputation: 11

Get label of form's select option instead if the value using javascript

HTML:

<select id="provider" class="chzn-select" name="provider">
    <option value="0">Please Select A Provider</option>
    <optgroup label="Canada">
        <option value="2043">Bell</option>
        <option value="2049">Fido</option>
        <option value="2061">Koodo Mobile</option>
        <option value="2056">Mobilicity</option>
    </optgroup>
</select>

JAVA SCRIPT:

$('#provider').val() Gives me the value such as "2043" if Bell is selected, how do i get the label text such as "Bell" if Bell is selected.

Upvotes: 1

Views: 120

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

You can find the selected option using selected-selector and then read its text

$('#provider option:selected').text()

Upvotes: 3

Related Questions