How would you set up a counter in javascript that goes from 5 to 0
This is what i have so far and it is not displaying in the div container "counter" for some reason...
[HTML]<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
#counter {border: 1px solid black; width: 100px; height: 100px; position: absolute; left: 450px; top: 10px;}
#leftcar {border: 1px solid black; width: 100px; height: 100px; position: absolute; left: 10px; top: 300px;}
#rightcar {border: 1px solid black; width: 100px; height: 100px; position: absolute; left: 800px; top: 300px;}
#explosion {border: 1px solid black; width: 100px; height: 100px; position: absolute; left: 450px; top: 300px;}
#controls {border: 1px solid black; width: 50px; height: 100px; position: absolute; left: 450px; top: 500px;}
</style>
<script>
function start () {
setContents ("counter",5);
var timer1= setTimeout("setContents('counter',4)",1000);
var timer2= setTimeout("setContents('counter',3)",2000);
var timer3= setTimeout("setContents('counter',2)",3000);
var timer4= setTimeout("setContents('counter',1)",4000);
var timer5= setTimeout("setContents('counter',0)",5000);
var timer6= setTimeout("setContents('counter',Go)",6000);
}
</script>
</head>
<body>
<div id="counter"></div>
<div id="explosion">
boom!
</div>
<div id="leftcar">
left car
</div>
<div id="rightcar">
right car
</div>
<div id="controls">
<form>
<input type="button" value="start" onclick="start();" />
<input type="button" value="reset" />
</form>
</div>
</body>
</html>[/HTML]
5 2065
setContents is undefined. Add the following to your code and it should work: - function setContents(id,val) {
-
document.getElementById(id).innerHTML = val;
-
}
setContents is undefined. Add the following to your code and it should work: - function setContents(id,val) {
-
document.getElementById(id).innerHTML = val;
-
}
thanks acoder. that helped !!
how exactly does the innerHTML = val work ? Well I know what it does now, it places the value in the box right?
Is there a way to position the value in the center of the box ?
also for some reason, it work in IE6.0 at all... am i missing anything?
thanks acoder. that helped !!
how exactly does the innerHTML = val work ? Well I know what it does now, it places the value in the box right?
Is there a way to position the value in the center of the box ?
innerHTML is not a standard but it provides an easy way to set or get the contents of an element. See this link and the MSDN link at the bottom of that page.
To position the value in the centre of the box, use CSS on the div:
also for some reason, it work in IE6.0 at all... am i missing anything?
Talk about IE bugs/problems/you name it! start is probably a reserved word, so you have to change the name of the function and it should work fine.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shane |
last post by:
:)
I am following a tutorial for php (hudzilla.org)
absolutely loving it
however I am having trouble with the counter example
<?php
// your content here...
$filename = 'counter.txt'; // our...
|
by: matthiasjanes |
last post by:
Hi,
Maybe someone of you can help me.
I'm trying to display an image in memory(open file) with an cgi script
- but it want work proberly:
I'm running an Cgi webserver (CgiServerGui.py).
...
|
by: Paul Rubin |
last post by:
I'd like to have a function (or other callable object) that returns
0, 1, 2, etc. on repeated calls. That is:
print f() # prints 0
print f() # prints 1
print f() # prints 2
# etc.
...
|
by: Matt K. |
last post by:
Hi there,
I have a form in an Access project that contains a subform which
displays the results of a query of the style "select * from
where = #a certain date#". In the main part of the form...
|
by: KitKat |
last post by:
Problem trying to figure this out, using a combo box selection I need to go
to each folder, Cam 1, Cam 2, Cam 4, Cam 6, Cam 7,and Cam 8 and display each
picture (from selection) from each folder...
|
by: blackstormdragon |
last post by:
Here were our instructions:
"My mother always took a little red counter to the grocery store. The counter was used to keep tally of the amount of money she would have spent so far on that visit to...
|
by: Pygmalion |
last post by:
I have found dozen of useful PHP counters on the web. However, nobody
is working for my web pages, since administrator does not want to
enable the possibility that PHP could be called from HTML. ...
|
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= |
last post by:
Hi, I am using Visual C# window to dispaly a set of questions with their
answers. The users should be able to move to the next question by clicking on
next button. I am going to use only one panel...
|
by: Telz |
last post by:
Hello,
I am a begginer to JavaScript (as you can probably see) currently working on a web page to display equipment info when "MouseOver"-ing a picture of the equipment. The info is stored in an...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |