[thelist] Option Value change
apathetic
timbooker at gmail.com
Sat Jun 5 07:09:25 CDT 2004
Let's say you have an array containing all of the options:
var optionList = {
'USA' : '098039284',
.. etc ..
}
Then all you need is some code to rewrite the contents of your select box:
functon rewriteOptions( selectBox ) {
selectBox.length = 0;
for( var opt in optionList ) {
selectBox.options[ selectBox.length ] = new Option( opt,
optionList[ opt ] );
}
}
Call that when the page loads, passing a reference to the select box.
Alternatively, you could simply use a document.write to generate the select box:
<select>
<script type="text/javascript">
for( var opt in optionList ) {
document.write( '<option value="' + opt + '">' + optionList[
opt ] + '</option>' );
}
</script>
</select>
These are only code samples off the top of my head. You might need to
fiddle around slightly to get it working.
Tim
--
http://www.apatheticgenius.com/
More information about the thelist
mailing list