Thursday, October 06, 2005

javascript "loop through all the options and test each one until"

You have to loop through all the options and test each one until you find
it, this example assumes you're testing against text value:

function setListbox(name, value, caseSensitive)
var oList = document.forms['abc'].elements[name];
var sTestValue = (caseSensitive ? value : value.toLowerCase());
var sListValue;
for (var i = 0; i < oList.options.length; i++)
sListValue = (caseSensitive ? oList.options[i].text :
oList.options[i].text.toLowerCase()); //change text to value if you wish to
compare by value of listbox.
if (sListValue == sTestValue)
oList.selectedIndex = i;


setListbox("Country", "Canada", true);

untested code provided by joe, dont know how that is, but anyway thanks

1 comment:

Anonymous said...

Thanks !

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: Its free and easy to use, we provide all sources at codeplex.

Facebook Badge