Dropdown and list box selection show/hides DIV

Discussion in 'Javascript' started by chris_huh, Aug 3, 2006.

  1. chris_huh

    chris_huh Guest

    I have a combo box whose values change depending on the value selected
    in the dropdown menu beforehand. Essentially the drop down has
    categories and the combo box are the actual topics.

    That all works fine but know i need to find a way to show some text,
    probably in a DIV, that is different for each of the values in the
    combo box.
    I have found a script that almost does this but it cannot work with the
    combo box being changable.

    Any one know how to do this?
     
    chris_huh, Aug 3, 2006
    #1
    1. Advertising

  2. chris_huh

    RobG Guest

    chris_huh wrote:
    > I have a combo box whose values change depending on the value selected
    > in the dropdown menu beforehand. Essentially the drop down has
    > categories and the combo box are the actual topics.
    >
    > That all works fine but know i need to find a way to show some text,
    > probably in a DIV, that is different for each of the values in the
    > combo box.
    > I have found a script that almost does this but it cannot work with the
    > combo box being changable.
    >
    > Any one know how to do this?


    Example, and caveat, below:

    <select onchange="changeText(this);">
    <option>one
    <option>two
    <option>three
    </select>
    <div id="xx"></div>
    <script type="text/javascript">
    function changeText(el){
    var txt = el.options[el.selectedIndex].text;
    var div = document.getElementById('xx');
    while (div.firstChild) div.removeChild(div.firstChild);
    div.appendChild(document.createTextNode(txt));
    }
    </script>


    Warning:
    - Feature detection omitted.
    - No error checking performed
    - Using onchange with select elements may create usability issues.


    --
    Rob
     
    RobG, Aug 3, 2006
    #2
    1. Advertising

  3. chris_huh

    Guest

    chris_huh wrote:
    > I have a combo box whose values change depending on the value selected
    > in the dropdown menu beforehand. Essentially the drop down has
    > categories and the combo box are the actual topics.
    >
    > That all works fine but know i need to find a way to show some text,
    > probably in a DIV, that is different for each of the values in the
    > combo box.
    > I have found a script that almost does this but it cannot work with the
    > combo box being changable.
    >
    > Any one know how to do this?


    // Make a text node:
    NewText = document.createTextNode(This_Is_My_Text_Variable+" or literal
    text");
    // Put it into div by id
    document.getElementById(DivObjectID).appendChild(NewText);

    hth

    If you used my system it would be half the code:
    // Put text in div
    PutIn($text("some text goes in here"), $(DivObjectID));

    http://darwinist.googlepages.com/htmldesktop.html
     
    , Aug 3, 2006
    #3
  4. chris_huh

    Guest

    chris_huh wrote:
    > I have a combo box whose values change depending on the value selected
    > in the dropdown menu beforehand. Essentially the drop down has
    > categories and the combo box are the actual topics.
    >
    > That all works fine but know i need to find a way to show some text,
    > probably in a DIV, that is different for each of the values in the
    > combo box.
    > I have found a script that almost does this but it cannot work with the
    > combo box being changable.
    >
    > Any one know how to do this?


    Oh, if you want to get the list index as well:

    // list is a reference to the select box:
    var optionvalue = list[list.selectedIndex].value;

    hth
     
    , Aug 3, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF1bA==?=

    remove a selection from a dropdown list box.

    =?Utf-8?B?UGF1bA==?=, Apr 26, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    656
    Chris
    Apr 28, 2005
  2. Vitthal Bhat via JavaKB.com
    Replies:
    1
    Views:
    5,511
    Deepak
    Jan 25, 2005
  3. Gnarlodious
    Replies:
    4
    Views:
    17,603
    elizas
    May 5, 2010
  4. Tim Donovan

    list box in a div selection on postback problem

    Tim Donovan, Feb 18, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    216
    Steve C. Orr [MVP, MCSD]
    Feb 18, 2005
  5. Adrian
    Replies:
    1
    Views:
    222
    Bullschmidt
    Feb 18, 2004
Loading...

Share This Page