Results 1 to 2 of 2

Thread: append a text input into div box

  1. #1
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default append a text input into div box

    How would one go about passing a "HTML text input form elements content" over to a text node that will be appended to a div box?

    In other words if a person were to type into say a textarea how would I make the text they are typing show up in a div box else where on the page?

    Please anyone!
    Thanks.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    First of all, a textarea and a text input are two different things. I will assume that you mean a text input:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function xFerText(el, id){
    document.getElementById(id).firstChild.nodeValue=el.value;
    }
    </script>
    </head>
    <body>
    <input type="text" onchange="xFerText(this, 'output');" onkeyup="xFerText(this, 'output');">
    <div id="output">&nbsp;</div>
    </body>
    </html>
    Or:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function xFerText(id1, id2){
    document.getElementById(id2).firstChild.nodeValue=document.getElementById(id1).value;
    }
    </script>
    </head>
    <body>
    <input id="input" type="text">
    <div id="output">&nbsp;</div>
    <input type="button" value="Go" onclick="xFerText('input', 'output');">
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •