Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change/modify the dropdownlist text by value using jquery

i have dropdownlist with the values:

<select id="myddl" name="myddl">
  <option value="1">One</option>
  <option value="2">Twooo</option>
  <option value="3">Three</option>
</select>

I need to change the text Twooo to Two using the value of the dropdownlist option(2). How can i do it in jquery?

like image 258
Prasad Avatar asked Dec 29 '09 11:12

Prasad


2 Answers

$('#myddl option[value=2]').text('Two');
like image 138
Kobi Avatar answered Oct 21 '22 00:10

Kobi


var myDLLField = $('select[id="myddl"]');
myDLLField.find('option[value="2"]').text("Two");   

or, in one line...

$('select[id="myddl"]').find('option[value="2"]').text("Two");  
like image 45
vapcguy Avatar answered Oct 21 '22 00:10

vapcguy