PDA

View Full Version : need some help with chained selects



DNice
03-18-2005, 06:09 AM
I'm currently using the Chained Selects dropdown menu javascript code, and would like to have it do something extra. What I really need it to do is display an image of what was selected from the dropdown menus.

heres an example of what I mean, in my dropdowns a user selects name, gang, and character image, i want to display a certain image based on the selections, so the user can decide if they want image x, y, or z. Hopefully I made that clear enough.

http://www.mk3design.com/dnice/gangland/test.php to see what i have sofar

DNice
03-21-2005, 10:32 PM
can I get some help? :confused:

mwinter
03-23-2005, 10:12 AM
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:


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:


/* Make sure value is not an empty string. */
if(option.value) {
document.images['avatar'].src = option.value;
}Mike