Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the text of an option by passing value of option with JQuery? [duplicate]

Possible Duplicate:
jQuery get select option text

I have a drop downlist as like:

<select id="systemMessageList" name="systemMessageList">
    <option value="-1">--- Choose One ---</option>  
    <option value="120">niempo</option>  
    <option value="119">quartero</option>  
    <option value="118">mileno</option>  
</select>

I want that: I will pass the value for example 119 and it will return the text quartero in JQuery?

like image 576
kamaci Avatar asked Dec 13 '22 14:12

kamaci


1 Answers

For the text of the selected option, you need:

$('#systemMessageList option:selected').text();

For the value you can just use

$('#systemMessageList').val();

Edit: the other answers are probably what you want. I'm just showing you how to get the text and value of whichever option is selected.

like image 170
Calum Avatar answered Jan 20 '23 00:01

Calum