Results 1 to 3 of 3

Thread: Write The Text

  1. #1
    Join Date
    Sep 2010
    Location
    Hi Stalker.
    Posts
    148
    Thanks
    16
    Thanked 3 Times in 3 Posts

    Question Write The Text

    Okay, I am having some troubles with this code, I want it to document.write what the user types into the text box then clicks the button.
    Though, when I click the button it document.writes nothing.
    Is there a problem?
    Code:
    <html>
    <head>
    <script>
    function write()
    {
    document.write("<html><head><title>Hi</title></head><body>");
    document.write(" " + txt + " ");
    document.write("</body></html>
    }
    txt=document.getElementById("intro").value;
    </script>
    <body>
    
    <input type="text" id="intro" value="Text" />
    <button onclick="write()">Test</button>
    </body>
    </html>
    I don't see anything wrong. I use Firefox.
    Help please?
    Last edited by [Nicolas]; 02-07-2012 at 12:15 AM.
    Daba! The Fantage-like website
    Virtual World in progress.
    Out of pure HTML, Javascript, and CSS. Oh, and poorly done Paint images.

  2. #2
    Join Date
    Mar 2011
    Posts
    1,899
    Thanks
    59
    Thanked 105 Times in 103 Posts
    Blog Entries
    4

    Default

    This should work -

    HTML Code:
    <html>
    <head>
    <script type="text/javascript">
    <!--
    function writer() {
    	var txt = document.getElementById("intro").value;
        document.write("<html><head><title>Hi</title></head><body>");
    	document.write(" " + txt + " ");
    	document.write("</body></html>");
    }
    //-->
    </script>
    </head>
    <body>
    <input type="text" value="bob" id="intro">
    <button onclick="writer()">Test</button>
    </body>
    </html>
    There were a couple of problems -

    HTML Code:
    document.write("</body></html>
    should look like this

    HTML Code:
    document.write("</body></html>");

    Also, you named your function write(). I don't think you can name a function write so I renamed it writer() and it worked fine in IE (May be different in Firefox...).

    Keyboard1333

  3. The Following User Says Thank You to keyboard For This Useful Post:

    [Nicolas] (02-06-2012)

  4. #3
    Join Date
    Sep 2010
    Location
    Hi Stalker.
    Posts
    148
    Thanks
    16
    Thanked 3 Times in 3 Posts

    Default

    Well, I had another problem.
    Now, nothing will write whatsoever.
    Code:
    <html>
    <head>
    <script type="text/javascript">
    <!--
    function writer() {
    	var txt = document.getElementById("intro").value;
                    document.write("<html><head><title>Hi</title></head><body>");
    	document.write(" " + html.body + " ");
    	document.write("</body></html>");
    }
    //-->
    </script>
    <title>My Code Tester</title>
    </head>
    <body bgcolor="yellow">
    <center>
    <noscript>Sorry, you don't have Javascript enabled so this script won't work.</noscript>
    <form name="html" id="html"> 
    Title: <input type="text" id="title" name="title" style="background-color:red;color:white;" value="bob"><br>
    Body: <textarea id="body" name="body" style="background-color:red;color:white;">bob</textarea><br><br>
    <button onclick="writer()" style="border: 0px;color: yellow;background-color: blue;height:50px;width:300px;font-size:30px;">~.~.~.~.~-Try-~.~.~.~.~</button>
    </form>
    </body>
    </html>
    I once again see nothing wrong in the code, it just won't work. I know it will because I made a website creator out of JavaScript using this technique.
    Please help.

    Edit: Terribly sorry, I noticed my error. I forgot to make the variable. Thank you again!
    Last edited by [Nicolas]; 02-07-2012 at 12:15 AM.
    Daba! The Fantage-like website
    Virtual World in progress.
    Out of pure HTML, Javascript, and CSS. Oh, and poorly done Paint images.

Bookmarks

Posting Permissions

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