PDA

View Full Version : My getcurTime() function isn't working after initial load



ad3cycles
01-15-2008, 02:55 AM
this is my external jscript

// JavaScript Document
function thisDoc(){

document.write(" <b>The Title:</b> ",document.title, "<br>");
document.write(" <b>The Location:</b> ", window.location, "<br>");
document.write(" <b>The Date last modified:</b> ", document.lastModified, "<br>");

}

function theBrows(){

document.write("<b>appCodeName:</b> ",
navigator.appCodeName, "<br>")
document.write("<b>appName:</b> ",
navigator.appName, "<br>")
document.write("<b>appVersion:</b> ",
navigator.appVersion, "<br>")
document.write("<b>platform:</b> ",
navigator.platform, "<br>")
document.write("<b>userAgent:</b> ",
navigator.userAgent, "<br>")

}

function yourDis(){

document.write( "<b>screen resolution:</b>", screen.width+'x'+screen.height, "<br>")
document.write( "<b>window dimensions:</b>", document.documentElement.clientWidth+'x'+document.documentElement.clientHeight, "<br>")

}

/*Add a last update statement at the bottom of Assignment5.htm, with the date supplied by the document's lastModified property. Display the date in the format of: Day Month Year at hour:minutes am/pm. Example: 25 October 2005 at 10:03 am. Create the function that formats the date in the external JavaScript file.*/

function dateForm(){
var months = new Array("January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December")

var today = new Date()
var hour = ""
var ext = ""
if (today.getHours() == 0) {
hour = 12
ext = "a.m."
} else if (today.getHours() < 12) {
hour = today.getHours()
ext = "a.m."
} else if (today.getHours() == 12) {
hour = 12
ext = "p.m."
} else {
hour = today.getHours() - 12
ext = "p.m."
}


// *** INSTRUCTOR COMMENTS: This is today's date...not the date the document was last modified. ***
// Today is Day, Month, Year
document.write("Last Modified: ",
today.getDate(), ", ",
months[today.getMonth()], " ",
today.getFullYear())

// at Hours:Minutes
document.write("at ", hour, ":",
today.getMinutes(), " ", ext)

}

function getcurTime() {
window.setTimeout( "getcurTime()", 1000 );
today = new Date();
self.status = today.toString();
}


and this is my html calling the function


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>


<script language="JavaScript" src="myJS_2.js" type="text/javascript"></script>

<title>Assignment 5</title>
</head>
<body>

<body onLoad="thisDoc(), theBrows(), yourDis(), dateForm(), getcurTime() ">

</body>
</html>

thanks in advance,
david

Twey
01-15-2008, 03:10 AM
It's broken.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">Transitional is outdated, and XHTML isn't supported by the most common browser yet. Stick to HTML 4.01 Strict for the time being.
<script language="JavaScript" src="myJS_2.js" type="text/javascript"></script>The language attribute is deprecated.
<body>

<body onLoad="thisDoc(), theBrows(), yourDis(), dateForm(), getcurTime() ">You have two opening <body> tags; in Javascript, multiple statements are separated by semicolons, not commas.
document.write(" <b>The Title:</b> ",document.title, "<br>");Don't use document.write() in this way. It will only work whilst the page is loading, for a start. Use DOM methods instead. <b> is presentational markup, and thus should be replaced by CSS. Read all the tutorials on http://www.howtocreate.co.uk/.

ad3cycles
01-16-2008, 03:42 AM
Thanks for the help!!!