Web Analytics Made Easy -
StatCounter Convert Javascript - CodingForum

Announcement

Collapse
No announcement yet.

Convert Javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Convert Javascript

    Hi All, how can I convert this script to a format to use the
    "document.getElementById('').innerHTML = '' + ;" and in the body of the html I could call it
    in the p paragraph tag? intead of calling between the script.

    By the way the script below works fine in the format that was written already
    I am just practicing with javascript and modifying the script for a better understanding.

    Let me know if it needs farther explanation please

    Thank you in advance for your help

    Code:
    var now = new Date();
    var todayAtMidn = new Date(now.getFullYear(), now.getMonth(), now.getDate());
    
    // Set start/end dates to a specified date (ISO format).
    var startDate = new Date("2016-06-09T15:20:00Z");
    var endDate = new Date("2016-09-29T15:20:00Z");
    
    // Compare the two dates by comparing the millisecond
    // representations.
    if (todayAtMidn.getTime() > startDate.getTime() && 
        todayAtMidn.getTime() < endDate.getTime()) {
        document.write("Specified date is within this range.");
    }
    else {
        document.write("Specified date is not in this range.");
    }

  • #2
    All JavaScript goes in a separate file attached to just before the </body> tag.

    document.write is as dead as Netscape 4.

    You need to throw away that 20 year old code that was called JavaScript and use the almost completely different modern language called JavaScript instead.

    If you want help with JavaScript that is to interact with a web page you need to provide both the JavaScript and the HTML.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

    Comment


    • #3
      Here you are:-

      Code:
          
      <!DOCTYPE html>
      <html>
      <body>
      
      <span id = "message"></span>
      
      <script type = "text/javascript">
      
      
      var now = new Date();
      var todayAtMidn = new Date(now.getFullYear(), now.getMonth(), now.getDate());
      
      // Set start/end dates to a specified date (ISO format).
      var startDate = new Date("2016-06-09T15:20:00Z");
      var endDate = new Date("2016-09-29T15:20:00Z");
      
      // Compare the two dates by comparing the millisecond
      // representations.
      if (todayAtMidn.getTime() > startDate.getTime() && todayAtMidn.getTime() < endDate.getTime()) {
      document.getElementById("message").innerHTML = "Specified is within this range";
      }
      else {
      document.getElementById("message").innerHTML = "Specified is not within this range";
      }
      
      </script>
      
      </body>
      </html>
      Apart from document.write() which is indeed obsolete, there is nothing wrong wth your code.

      So do you find that pornography fills a hole in your life? - Eddie Mair, BBC Radio 4
      Last edited by Philip M; Sep 22, 2016, 04:09 AM.

      All the code given in this post has been tested and is intended to address the question asked.
      Unless stated otherwise it is not just a demonstration.

      Comment


      • #4
        Excellent Philip, thank you very much

        Comment

        Working...
        X