Is there some prebuilt code (most likely javascript) that would do this?

Discussion in 'Programming' started by Josh-H, May 31, 2008.

  1. #1
    Hello.

    I need some kind of javascript I believe so that when I typed text into a form field, the text also shows up on the other side of the page under a header as plain text. Without a refresh needed obviously or without needing to submit form.

    If you don't understand what I mean I'll try to explain better :)

    Thanks, +REP to helpers.
     
    Josh-H, May 31, 2008 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    var obj = document.getElementById("TextAreaId");
    obj.onChange = function (){
         document.getElementById("NewContentAreaId").innerHTML = obj.value;
    }
    Code (markup):
    that may work :p
     
    crath, May 31, 2008 IP
  3. Josh-H

    Josh-H Active Member

    Messages:
    406
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Thanks but I've never really used javascript before so how would I go about using it?

    I tried:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <script>
    var obj = document.getElementById("textarea");
    obj.onChange = function (){
         document.getElementById("div").innerHTML = obj.value;
    }
    </script>
    </head>
    
    <body>
    
    <textarea name="textarea" cols="7" rows="7" id="textarea"></textarea>
    
    <div id="div"></div>
    
    </body>
    </html>
    
    
    Code (markup):
    But that didn't work :p
     
    Josh-H, May 31, 2008 IP
  4. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #4
    here, you can play with this
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    	<title>Untitled Document</title>
    </head>
    <body>
    	<textarea name="textarea" cols="7" rows="7" id="textarea" onchange="document.getElementById('div').innerHTML=this.value">asdffewf2</textarea>
    	<div id="div">asdf</div>
    </body>
    </html>
    Code (markup):
     
    crath, May 31, 2008 IP
  5. Josh-H

    Josh-H Active Member

    Messages:
    406
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #5
    Thats brilliant. Thank you!
     
    Josh-H, May 31, 2008 IP
  6. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #6
    no problem :)
     
    crath, May 31, 2008 IP