1

I have data coming in the following format from external system

<option value="1">GM </option>
<option value="2">Honda </option>
<option value="3">Ford </option>
<option value="4">Toyota </option>

and I am adding it to the combobox . But based on the value in the database ( example Ford, or GM) , I have to select that one by default . The value in the database is the display value coming from the external system , not exactly the VALUE in options . I can select based on the VALUE in options , but how do it selected based on the display value .

Thanks for all your help

Regards Kiran

Bujji
  • 1,717
  • 10
  • 41
  • 66

1 Answers1

3

I've tested this and it does what you need

$("#selectId").val ($("#selectId option:contains('Honda')").val())

In two steps 1) find the value for the string you wish to find 2) Set that to be the selected value for the combo box.

There seems to be other solutions out there, but i'd suggest that this is the safest crossbrowser.it even works in IE6 :D

John
  • 106
  • 2
  • 13