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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.write problem

    thise COMPLEX code does not work

    <html><head><script>
    var testvar="shishsihsi";
    function Write(){document.write(testvar)}
    </script></head>
    <body onClick="Write()">test test test</body>

    i know very big ( )

    however it delets the test test test when it writes the testvar

    whats wrong and how do i fix it?

    thanks for any help

  • #2
    New Coder
    Join Date
    Dec 2003
    Location
    Soraga, Trentino, Italy
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the document.write method writes something on the page. If you use it when the page has been completely loaded, it deletes all and writes only that sentence...

  • #3
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,696
    Thanks
    0
    Thanked 232 Times in 227 Posts
    Hi there JAVAEOC,

    ..........so use 'innerHTML'
    like this....
    <html>
    <head>
    <script type="text/javascript">
    var testvar="shishsihsi";
    function Write()
    {
    document.getElementById("foo").innerHTML=testvar;
    }
    </script>
    </head>
    <body onclick="Write();">
    <p>test test test</p>
    <div id="foo"></div>
    </body>
    <html>

    This works fine except for 'Opera' where you have to click
    within the 'p' for it to function

    cthead

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    SC
    Posts
    936
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cool thx.

  • #5
    New Coder
    Join Date
    Oct 2002
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.write .... update script??

    hi,

    how can this be updated so that I can use multiple document.write? I've tried:

    <script type="text/javascript">
    document.write="a";
    document.write="b";
    function Write()
    {
    document.getElementById("foo").innerHTML=document.write;
    }
    </script>

    It works but seems to write the last one ie. b

    thanks,

    Death = $Mill

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: document.write .... update script??

    Originally posted by deathmill
    hi,

    how can this be updated so that I can use multiple document.write? I've tried:

    <script type="text/javascript">
    document.write="a";
    document.write="b";
    function Write()
    {
    document.getElementById("foo").innerHTML=document.write;
    }
    </script>

    It works but seems to write the last one ie. b

    thanks,

    Death = $Mill
    Use the + operator to concatenate the two strings.

    eg:
    Code:
    <script type="text/javascript">
    document.write="a";
    document.write+="b";
    function Write()
    {
    document.getElementById("foo").innerHTML=document.write;
    }
    </script>
    .....Willy

    BTW: document.write is not an appropriate variable name.
    You need to change that to something which is not a reserved word or method.

  • #7
    Regular Coder oldcrazylegs's Avatar
    Join Date
    Feb 2004
    Location
    East Moline Illinois USA
    Posts
    414
    Thanks
    4
    Thanked 5 Times in 4 Posts

    Easy way to do document.write

    Instead of writing document.write my self I use this easy converter at about.com. All you do is copy and paste your HTML source into it and click on CONVERT. It is many times faster.

    http://javascript.about.com/library/...ldocwriter.htm


  •  

    Posting Permissions

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