Date: 11/22/05 (Javascript Community) Keywords: no keywords Why does this: alert ("start clocks"); // Simple alert message to be sure the script source is available to the site. c0 = ""; c1 = ""; c2 = ""; c3 = ""; c4 = ""; c5 = ""; c6 = ""; c7 = ""; c8 = ""; c9 = ""; colon = ""; function write_digit (digit) { switch (digit) { case "0": document.write(c0); break; case "1": document.write(c1); break; case "2": document.write(c2); break; case "3": document.write(c3); break; case "4": document.write(c4); break; case "5": document.write(c5); break; case "6": document.write(c6); break; case "7": document.write(c7); break; case "8": document.write(c8); break; case "9": document.write(c9); break; default: document.write(colon); } } function wc() { date = new Date(); // set the date variable. year = date.getFullYear(); // get the full year from the date. yearString = year.toString(); // convert the year into a string, so that we can split it. ysub1 = yearString.substring(0,1); // get the first digit of the year ysub2 = yearString.substring(1,2); // get the second digit ysub3 = yearString.substring(2,3); // get the third digit ysub4 = yearString.substring(3,4); // get the fourth digit month = date.getMonth() + 1; // get the month. Since the months array is 0-based, // add 1 to get the commonly recognised month. monthString = month.toString(); // convert the month to a string for splitting if (monthString.length != 2) { // if the monthString is not two characters long msub1 = "0"; // set the first digit to "0" msub2 = monthString.substring(0,1); // get the second digit. } else { // if the monthString is 2 digits msub1 = monthString.substring(0,1); // get the first digit msub2 = monthString.substring(1,2); // get the second digit } day = date.getDate(); // get the day portion of the date. dayString = day.toString(); // convert it to a string. if (dayString.length != 2) { // if the dayString is not 2 digits dsub1 = "0"; // set the first digit dsub2 = dayString.substring(0,1); // get the second digit } else { // if it is 2 digits dsub1 = dayString.substring(0,1); // get the first digit dsub2 = dayString.substring(1,2); // get the second digit } document.write(date); // write the date. -- this works..... alert (date); // TESTING -- this doesn't, and the script just ends here. document.write(" This is (if it's not obvious) for a digital clock to appear on the page with the client-side time. Ultimately, I want to get it updating "live". I've been told I need to use setTimeout("wc()", 1000) to get it to update every second. Source: http://community.livejournal.com/javascript/83753.html
|