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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Populating textarea when dropdown box is changed

    There ia an empty textarea and a pre-populated drop-down box with a default message. How can I get the text selected from the drop-down box(onChange) into the textarea using javascript?

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this might do it...

    Code:
    <html>
    <head>
    <title>-</title>
    
    <script type="text/JavaScript">
    
    function showText(){
    var F, opt;
    F = document.oForm;
    opt = F.oSel.options;
    
    F.oTxt.value = opt[opt.selectedIndex].text;
    
    }
    </script>
    
    </head>
    <body>
    
    <form name="oForm">
    
    <select name="oSel" size="3" 
    onchange="showText()">
    
    <option>lorem</option>
    <option>ipsum</option>
    <option>dolar</option>
    
    </select>
    
    <textarea name="oTxt" cols="10" rows="5">
    </textarea>
    
    </form>
    
    </body>
    </html>
    hmm... ?

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    shorter code:

    <select name="oSel" size="3"
    onchange="this.form.oTxt.value=this.options[this.selectedIndex].text">
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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