Javascript Examples

From I Will Fear No Evil
Jump to navigation Jump to search

I HATE JavaScript

Did I mention I hate it? Well that does not matter. It is used all over, and I am going to have to learn to deal with it.. Here are some examples and notes that can be integrated and not cause troubles in most applications

JS clock on page

Found example at display-clock-inside-the-html-page-or-div

<script>
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;
    var t = setTimeout(startTime, 500);
}
function checkTime(i) {
    if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}
</script>
<body onload="startTime()">
<div id="txt"></div>