|
Tip Top... Hey, hey! We're good to go with the running digital clock this time around. This is a big, involved piece of code that you'll love. I do. Of course... I wrote it! Click the button to get the time.
As we did with the last script we tore apart, let's start at the bottom of this one, with the HTML form flags.
Yes! I know, I know... Before the barrage of e-mail telling me the use of a button to start the clock is silly and that the clock has to be started again each time the user leaves and returns to the page and the clock would be much better served starting with an onLoad command in the body, I say to you that I know all of that. I am using the button as a teaching tool. It will allow me to talk about triggering the function and talk about how the script reacts. But, so we're all happy... Yes, it is a much better idea to trigger this clock when the page loads through the use of an onLoad="RunningClock()" trigger in the BODY flag. That way every time the page is reloaded, the body flag runs and the clock starts up with no user input. Now that I've said that, we shall get started. The HTML Form Elements They look like this:
<FORM NAME="clock">
<INPUT TYPE="text" name="clockface"> The form flags create two elements: A text box, where the output of the clock script will display, and a button that triggers the function. The form itself is named clock. That makes sense. The text box that will contain the clock face is called clockface. Clever names, huh? The button is basic JavaScript that carries an onClick event handler that triggers the function RunningClock(). So, now we have the info needed to apply the JavaScript to these form elements. You should be able to pick out by now that the text box above will be represented by the hierarchy statement:
What's Happening? Most people tell me that when they read these Tips, the first thing they do is take the script from the page and paste it into an HTML document. Because of that I like to take the first Tip on each new script and simply explain the script's construction.
It's a great script that looks really smooth sitting on a page. I think it looks great sitting on this page, don't you? Next Week: Grabbing and Altering the Hour
HTML Goodies 30-Step Primer Series and take the knowledge home with you in JavaScript Goodies! on your Web pages here! |