PDA

View Full Version : First JavaScript :D


Remember
01-28-2009, 03:44 PM
<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>
<input type="button" value="Start timer!" id="timer" onclick="startTime()" >
<div id="txt"></div>
</body>
</html>



I know, it's in PHP tags but it makes it look cooler D:
Click a button, and it starts a clock.
Simple, fun for me to do.
I'll add some updates in a bit, JavaScript is more fun than I thought it would be.

killerman99
01-28-2009, 04:27 PM
You can add a much simpler code in BASIC programming, but I'm to lazy to post it right now. I'll get it for you later though.

Remember
01-28-2009, 04:45 PM
You can add a much simpler code in BASIC programming, but I'm to lazy to post it right now. I'll get it for you later though.
Will it have a sexy button?
:D