
Originally Posted by
DNice
Hopefully I made that clear enough.
Not really. In any case, you can find out which option element is currently selected by accessing the selectedIndex property of a select element. This produces a value between 0 and length-1. To get at that option, you can then use the options collection:
Code:
var select = document.forms['my-form'].elements['my-select'],
index = select.selectedIndex,
option = select.options[index];
The value property yields the string in the value attribute for that option element, whilst the text property provides access to the text content.
For example, you could store the URL of an image in the value attribute of each of the "final" option elements. When selected, you could then assign this URL to the src property of an img element:
Code:
/* Make sure value is not an empty string. */
if(option.value) {
document.images['avatar'].src = option.value;
}
Mike
Bookmarks