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?
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.
try this:
$('option[value="'+$('#systemMessageList').val()+'"]').text();
so if 119
is selected it will return: quartero
or you can create some sort of function that gets the text for any option value:
function getOptionText(option){
return $('option[value="'+option+'"]').text();
}
getOptionText(119); // yields quartero
var text = $('#systemMessageList option[value="119"]').text();
Try this:
function getOptionText(value){
return $('#systemMessageList option[value="' + value + '"]').text();
}
alert(getOptionText(119));
精彩评论