www.webdeveloper.com
Results 1 to 2 of 2

Thread: document.write...

  1. #1
    Join Date
    Apr 2009
    Posts
    12

    document.write...

    I felt like trying something new and making document.write() used on command. I used a button to trigger the document.write(), but it removes the button and it does write the text, though.

    Code:
    <html>
    <head>
    <title>
    Hello</title>
    <script type="text/javascript" language="javascript">
    function box(a){
    		 document.write(a);
    }
    </script>
    </head>
    <body>
    <h1><input type="button" onClick="box('Wheeeeeeee')" value="Jawesome."></input></h1>
    </body>
    </html>
    How do I make it so that when the event is triggered, the document.write() will occur wherever I want it to.

    What I mean is I don't want the text in document.write() to appear instead of the button, I want the button to make the document.write() to appear anywhere I want it to. If there are any other ways of doing this, do tell.

  2. #2
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    document.write simply output the content in canvas as it were regular HTML content. if you want to make it appear on a specific place you would have to use HTML to markup the printed content, either when pressing the button or when calling document.write while loading document. so for example, you pass the string to your method box and in the method you wrap the string with HTML:
    Code:
    function box(a){
    document.write("<span style='here place css rules for positioning element'>", a, "</span>");
    }
    however, the truth is that the function isn't replacing the string for the button. instead, it completely clear the content in browser to print new content. so, document.write is bad for appending new content to canvas. you might want to try with innerHTML so that it don't appear that string replace the button:

    Code:
    <input ... />
    <p id='newcontent'></p>
    <script>
    function box(a){
    document.getElementById('newcontent').innerHTML = a;
    }
    </script>
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles