Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2003
    Location
    scotland, edinburgh
    Posts
    176
    Thanks
    5
    Thanked 1 Time in 1 Post

    Show text after selecting something from a listbox

    Can someone show me how I would make this happen

    I have a listbox and depending on what what you selected differnt text will pop up underneath the listbox with out the page realoading.

    It seems simple I know but i dont know where to start

    Thanks

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    <select name="s" onchange="document.getElementById('desc').innerHTML=this.options[this.selectedIndex].value">
    <option value="">Select one</option>
    <option value="blah blah blah">item 1</option>
    <option value="foo foo foo">item 2</option>
    <option value="he he he">item 3</option>
    </select>
    <div id="desc"></div>

  • #3
    Regular Coder
    Join Date
    Aug 2003
    Location
    scotland, edinburgh
    Posts
    176
    Thanks
    5
    Thanked 1 Time in 1 Post
    thats exactly what I want although how would I be able to format it like add new lines and add html like tables.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var arr = new Array();
    arr[0] = '';
    arr[1] = 'This is a <a href="http://www.google.com/">link</a>.';
    arr[2] = 'This is in line 1.<br />This is in line 2.';
    arr[3] = '<span class="redmsg">This text uses a red Verdana font.</span>';
    //...and so on
    </script>
    <style type="text/css">
    .redmsg {font:normal 12px Verdana; color:red;}
    </style>
    </head>
    <body>
    <form>
    <select name="s" onchange="document.getElementById('desc').innerHTML=arr[this.selectedIndex]">
    <option value="">Select one</option>
    <option value="item 1">item 1</option>
    <option value="item 2">item 2</option>
    <option value="item 3">item 3</option>
    </select>
    <div id="desc"></div>
    </form>
    </body>
    </html>


  •  

    Posting Permissions

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