SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,208
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    printing a variable

    Code:
    <script type=text/javascript>
       var now=new Date();
    </script>

    I like to print the variables now.

    How can I print it?

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to output it on the HTML page first. After doing that you can print it.

  3. #3
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,208
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pepejeria View Post
    You need to output it on the HTML page first
    How can I output it ?

    Code:
     trial code
    
    <script type=text/javascript>
       var now=new Date();
    </script>
    
    <output>
    now
    </output>

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <div id="output"></div>
    
    <script>
    var outputNode = document.getElementById("output");
    var now = new Date();
    outputNode.innerHTML = now;
    </script>

  5. #5
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,208
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pepejeria View Post
    Code:
    <div id="output"></div>
    
    <script>
    var outputNode = document.getElementById("output");
    var now = new Date();
    outputNode.innerHTML = now;
    </script>
    The following trial code produces a blank page.

    Code:
    trial code2
    
    <div id="output"></div>
    
    <script>
    var outputNode = document.getElementById("output");
    var now = new Date();
    outputNode.innerHTML = now;
    </script>
    I like to print the current time.

  6. #6
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean it prints a blank page. How about providing the code to see what is wrong?

  7. #7
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,208
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pepejeria View Post
    What do you mean it prints a blank page. How about providing the code to see what is wrong?

    test.html page has the code like the following.

    Code:
    test.html with the code you provided
    
    <html>
    
    <div id="output"></div>
    
    <script>
    var outputNode = document.getElementById("output");
    var now = new Date();
    outputNode.innerHTML = now;
    </script>
    
    </html>
    If I see it with my browse, it shows nothing( blank, white).

    I want the browsing result shows the variables value instead of blank.

  8. #8
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that doesn't work, since it is not proper HTML... You are missing some tags.

  9. #9
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <html>
    <body>
    <div id="output"></div>
    <script>
    var outputNode = document.getElementById("output");
    var now = new Date();
    outputNode.innerHTML = now;
    </script>
    </body>
    </html>


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
  •