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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to Reset innerHTML?

    Hi,
    I am using the following code to try to replace "hello" inside DIV. When I type in the field, it should clear 'hello' and then display what I type in the field one letter at a time. But it doesn't clear hello and it just show what I type in an additional line, what's wrong?
    many thanks.
    Code:
    <head>
    <script language='javascript'>
    function mirror(){
      document.getElementById("theDiv").innerHTML=document.getElementById("txtarea").value;
    }
    </script>
    </head>
    <body>
    <input name="txtarea" id="txtarea" type="text" onKeyUp="mirror();">
    <div name="theDiv" id="theDiv">hello
    </div>
    </body>

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Works fine for me in FF1.5/Mac.
    In which browser are you experiencing problems?

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Yes, it should work in all the modern browsers. At least if you use a doctype and the correct type for the script tag:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    meta http-equiv="Content-Style-Type" content="text/css">
    <
    meta http-equiv="Content-Script-Type" content="text/javascript">
    <
    script type="text/javascript">
    function 
    mirror(v){
    document.getElementById('theDiv').innerHTML=v;
    }
    </script>
    </head>
    <body>
    <input type="text" onkeyup="mirror(this.value)"><br>
    <div id="theDiv">Hello!</div>
    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Kor
    Have you checked whether your browser is javascript disabled?
    Quote Originally Posted by dealmaker
    But it doesn't clear hello and it just show what I type in an additional line
    I presume from the fact that it is adding the text, that js is enabled.


    [edit]

    I guess you just realised that too.

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    yea... I have had already corrected the post...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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