PDA

View Full Version : please help!!



grafixgirl
12-09-2008, 05:00 PM
i dont know javascript at all..im just a copy and paster :)
i used this script for a countdown timer and workds great with IE but not with firefox..i want to know how to add an if, else statement so that it will just show 5:00 in the scripts place...or if u can just tell me how to make it cross browser compatible then that would be even better :)
the site is www.acaiburnfree.com
and here is the code
<SCRIPT language=JavaScript>
//New phone function end

var sec = 00; // set the seconds
var min = 5; // set the minutes

function countDown() {
sec--;
if (sec == -01) {
sec = 59;
min = min - 1;
} else {
min = min;
}
if (sec<=9) { sec = "0" + sec; }
time = (min<=9 ? "0" + min : min) + ":" + sec + "";
if (document.getElementById) { theTime.innerHTML = time; }
SD=window.setTimeout("countDown();", 1000);
if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); }
}

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent(function() {
countDown();
});

</SCRIPT>


then where i have the timer showing up
<SPAN id=theTime>

thanks so much!!

jscheuer1
12-09-2008, 06:21 PM
Use document.getElementById, close the span tag (important changes highlighted):


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
//New phone function end

var sec = 00; // set the seconds
var min = 5; // set the minutes

function countDown() {
sec--;
if (sec == -01) {
sec = 59;
min = min - 1;
} else {
min = min;
}
if (sec<=9) { sec = "0" + sec; }
time = (min<=9 ? "0" + min : min) + ":" + sec + "";
if (document.getElementById) { document.getElementById('theTime').innerHTML = time; }
SD=window.setTimeout("countDown();", 1000);
if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); }
}

function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent(function() {
countDown();
});

</script>
</head>
<body>
<span id=theTime></span>
</body>
</html>

grafixgirl
12-09-2008, 06:50 PM
OMG it fixed it!!! thank u soooo much! u rock! :)