Little Help required with getElementbyId function.

Discussion in 'JavaScript' started by arpit13, Aug 6, 2011.

  1. #1
    hi,

    i want a simple display of two things: a textarea and how will it look.
    i hope u understand me.
    this is the code i used:
    
    <script language='javascript'>
    document.getElementById('testDemo').innerHTML="{$text}";
    function doEdit() {
    document.getElementById('testDemo').innerHTML=document.getElementById('tos').value;
    }
    
    
    </script>
    <textarea name='tos' id='tos' cols=40 rows=15 onmousemove='doEdit()'>{$text}</textarea></td><td><div id='testDemo'></div>
    
    Code (markup):

    {$text} is a variable and is not the source of error,i am sure.
    the code worked,until i refreshed few times. plz help me.
     
    arpit13, Aug 6, 2011 IP
  2. jaimegm

    jaimegm Member

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    Have you tried something like
    <textarea name='tos' id='tos' cols=40 rows=15 onmousemove='doEdit()' value='{$text}'></textarea> ?
     
    jaimegm, Aug 6, 2011 IP
  3. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #3
    that made my code even worse.
    there is no "value" attribute for textarea
     
    arpit13, Aug 6, 2011 IP
  4. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #4
    jaimegm, PM me about the awesome stuff you're smoking man. Seems like you're pretty stoned. 
    Oh yea, <textarea> doesn't have a "value" attribute BTW..... 
     
    Andre91, Aug 6, 2011 IP
  5. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #5
    i tried this and it worked 100% fine:
    
    <script language='javascript'>
    
    function doEdit() {
    document.getElementById('testDemo').innerHTML=document.getElementById('tos').value;
    }
    
    
    </script>
    <textarea name='tos' id='tos' cols=40 rows=15 onmousemove='doEdit()'>{$text}</textarea><div id='testDemo'>{$text}</div>
    
    Code (markup):
     
    arpit13, Aug 6, 2011 IP
  6. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #6

    the problem with your code is that you executed document.getElementById('testDemo').innerHTML="{$text}"; before the <div id='testDemo'></div> element is created, what you can do is move your script after <div id='testDemo'></div>. it will look something like this...

      <textarea name='tos' id='tos' cols=40 rows=15 onmousemove='doEdit()'>{$text}</textarea></td><td><div id='testDemo'></div> 
    <script language='javascript'> 
    document.getElementById('testDemo').innerHTML="{$text}"; 
    function doEdit() { 
      document.getElementById('testDemo').innerHTML=document.getElementById('tos').value; 
    } 
    </script>
    
    HTML:
     
    JohnnySchultz, Aug 8, 2011 IP
  7. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #7
    i don't think that matters.........
    the code i provided is not the complete code m using.
    in the actual code, <div id='testDemo'></div> came first
    anyways thx for the effort........
     
    arpit13, Aug 8, 2011 IP