Results 1 to 3 of 3

Thread: need some help with chained selects

  1. #1
    Join Date
    Mar 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation need some help with chained selects

    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

  2. #2
    Join Date
    Mar 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    can I get some help?

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •