How to implement this JavaScript in HTML
NickName:Dragana Ask DateTime:2014-10-30T19:55:47

How to implement this JavaScript in HTML

This is a JavaScript showing time hour, minute and seconds now seconds are ticking minutes change it's not static i have problem.How to implement it in HTML page ?

<script type="text/javascript">
  function startTime() {
      var today = new Date();
      var h = today.getHours();
      var m = today.getMinutes();
      var s = today.getSeconds();
      m = checkTime(m);
      s = checkTime(s);
      document.getElementById('txt').innerHTML = h + ":" + m + ":" + s;
      t = setTimeout('startTime()', 500);
  }

  function checkTime(i) {
      if (i < 10) {
          i = "0" + i;
      }
      return i;
  }
</script>

Copyright Notice:Content Author:「Dragana」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/26652324/how-to-implement-this-javascript-in-html

Answers
Ненад 2014-10-30T12:17:16

Edit your body tag to \n\n<body onload=\"startTime()\">\n<span id=\"txt\">10:26:07</span>\n\n\nThan add bellow code where you want clock to appear ",


EpokK 2014-10-30T12:02:14

Just do it:\n\n<span id=\"txt\"></span>\n\n<script type=\"text/javascript\">\n function startTime() {\n var today = new Date();\n var h = today.getHours();\n var m = today.getMinutes();\n var s = today.getSeconds();\n m = checkTime(m);\n s = checkTime(s);\n document.getElementById('txt').innerHTML = h + \":\" + m + \":\" + s;\n t = setTimeout('startTime()', 500);\n }\n\n function checkTime(i) {\n if (i < 10) {\n i = \"0\" + i;\n }\n return i;\n }\n\n startTime();\n</script>\n",


Roko C. Buljan 2014-10-30T12:02:56

\nYou need an element on your page with ID txt (see your script.)\nYou need to start/call your function execution startTime();\nIn order to allow the JS DOM parser to find your #txt place your <script> before the closing </body> tag.\n\n\n\r\n\r\n<div id=\"txt\"></div>\r\n\r\n<script type=\"text/javascript\">\r\n function startTime() {\r\n var today = new Date();\r\n var h = today.getHours();\r\n var m = today.getMinutes();\r\n var s = today.getSeconds();\r\n m = checkTime(m);\r\n s = checkTime(s);\r\n document.getElementById('txt').innerHTML = h + \":\" + m + \":\" + s;\r\n t = setTimeout('startTime()', 500);\r\n }\r\n\r\n function checkTime(i) {\r\n if (i < 10) {\r\n i = \"0\" + i;\r\n }\r\n return i;\r\n }\r\n \r\n startTime(); // Execute\r\n</script>",


More about “How to implement this JavaScript in HTML” related questions

How to implement this JavaScript in HTML

This is a JavaScript showing time hour, minute and seconds now seconds are ticking minutes change it's not static i have problem.How to implement it in HTML page ? &lt;script type="text/javasc...

Show Detail

How to implement a list container in html / Javascript?

Hi i am new to Html and javascript and want some suggestion on how to implement a list container in Html, like when the user selects one of the files using browse b button then those file should ap...

Show Detail

How to implement intelxdk using JavaScript in HTML?

How &amp; where should I implement this JavaScript method below in my index.html file? I am using this code to access the native code of android in intelxdk smsplugin.startReception(successCallback(

Show Detail

How can I implement a Javascript/HTML Playground with Javascript?

I would like to implement a simple Javascript Playground like jsFiddle and was wondering on the best way to achieve this. From the way jsfiddle works, it creates an iframe with the submitted HTML/

Show Detail

How to implement html uncode function with JavaScript

html.replace(/&amp;lt;/g, "&lt;").replace(/&amp;gt;/g, "&gt;" is there any JavaScript function can implement this function, seems like unescape function or escape function, which can convert displ...

Show Detail

Can someone tell me how to implement this Javascript? HTML CSS

I found this awesome link with a scroll-to-top button that I'd like to add to my web page. Can someone tell me how to implement the javascript part? I tried inserting it at the bottom of my html pa...

Show Detail

Javascript/HTML: How to implement a button that adds a click counter on click?

I understand how to implement a single click counter. However, I am struggling to figure out how to implement a button that will duplicate the click counter, while also allowing me to use the same

Show Detail

How to implement an XSLT file within HTML

I'm trying to display a whole XML database through an HTML file, but in order to display all the elements, I need XSLT. Since I used Javascript for manipulation with the way the database is display...

Show Detail

How to Implement DOM Data Binding in JavaScript

Please treat this question as strictly educational. I'm still interested in hearing new answers and ideas to implement this tl;dr How would I implement bi-directional data-binding with JavaScript?

Show Detail

How to implement markdown in html and js

I am working on a website where a user can input a message that is sent to another user. I want to implement Markdown so the user can use markdown on the message to be able to bold the message and ...

Show Detail