I want to be able to do a string match on some data being populated via AJAX into a selectbox.

currently, it works if I identify the option index, but not the option value (i.e. match it's position in the select, as opposed to matching the the value of the text).

for instance (searchForm is the name of the form that the selectbox resides in. departureList is the name of the select box.):

PHP Code:

// var departureCity = "Calgary";

var departureNum 1;

document.searchForm.departureList.options[1].value == departureNum){

document.searchForm.departureList.options[1].selected true;

I hardcoded the value options[1] because it's part of a longer loop, and it's not necessary for this portion.

Based on that code, if I had Calgary, Chicago, Detroit, Toronto as my 4 cities, me choosing options[1] would choose Calgary. That's all well and good, but the data that populates this selectbox comes from an XML file. That means one day it could be Buffalo, Calgary, Chicago, Detroit, Toronto... meaning that options[1] no longer represents Calgary, but Buffalo.

What I'd prefer it to do, is match the string "Calgary", as opposed to trying to match it's postion in the selectbox.

Basically, I'd rather do something like this:

PHP Code:

var departureCity "Calgary";

Text of selext box  == departureCity){

Make that value defaulted to selected;