TulipTools Internet Business Owners and Online Sellers Community

Full Version: Need Help With Javascript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to teach myself javascript, and I don't understand how some of it works. For example, the code snippet below is from w3schools. It is a simple numerical clock/timer.
This may seem to be a stupid question (I feel stupid asking it  Tard), but how does the script know where to acquire the correct time? :-[ Tard Iamwithstupid

Code:
<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
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>
</head>

<body onload="startTime()">
<div id="txt"></div>
</body>
</html>
It reads your computer's mind.
I knew it was a stupid question.  Tard  Thanks, reg. :-[

Is that what the variable is telling it to do----------get the time from the pc viewing the page? Icon_scratch

Code:
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();