views:

42

answers:

0

Hi! I have a Select-Box like this:

<select id="mySelect">
    <option value="1">Entry 1</option>
    <option value="2">Entry 2</option>
    <option value="3">Entry 3</option>
    <option value="4">Entry 4</option>
    <option value="5">Entry 5</option>
</select>

How can I set the val of my Select-Box by knowing only the text()-Attribute of the option? F.i., I want to set the selection to the option with text 'Entry 2'.

After trying long time, I got it working:

$('#mySelect option').filter(function() {
      if ($(this).text() == 'Entry 2') 
      {
        $('#mySelect').val(($(this).val()));
      }
    });

Is there anything better?