Javascript Examples: Difference between revisions

From I Will Fear No Evil
Jump to navigation Jump to search
(Created page with "===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 [https://stackoverflow.com/questions/40959133/display-clock-inside-the-html-page-or-div display-clock-inside-the-html-page-or-div] <pre> <script> function startTime() { var today =...")
 
m (Chubbard moved page Javascript to Javascript Examples)
 

Latest revision as of 11:28, 5 July 2023

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>