Results 1 to 2 of 2

Thread: document.write...

  1. #1
    Join Date
    Apr 2009


    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.

    <script type="text/javascript" language="javascript">
    function box(a){
    <h1><input type="button" onClick="box('Wheeeeeeee')" value="Jawesome."></input></h1>
    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
    Odenton, MD
    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:
    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:

    <input ... />
    <p id='newcontent'></p>
    function box(a){
    document.getElementById('newcontent').innerHTML = a;
    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