473,549 Members | 2,803 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Displaying a Counter using setContents

16 New Member
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.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitl ed 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("set Contents('count er',4)",1000);
var timer2= setTimeout("set Contents('count er',3)",2000);
var timer3= setTimeout("set Contents('count er',2)",3000);
var timer4= setTimeout("set Contents('count er',1)",4000);
var timer5= setTimeout("set Contents('count er',0)",5000);
var timer6= setTimeout("set Contents('count er',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]
Feb 14 '07 #1
5 2082
acoder
16,027 Recognized Expert Moderator MVP
setContents is undefined. Add the following to your code and it should work:
Expand|Select|Wrap|Line Numbers
  1. function setContents(id,val) {
  2.  document.getElementById(id).innerHTML = val;
  3. }
Feb 14 '07 #2
jasonchan
16 New Member
setContents is undefined. Add the following to your code and it should work:
Expand|Select|Wrap|Line Numbers
  1. function setContents(id,val) {
  2.  document.getElementById(id).innerHTML = val;
  3. }

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 ?
Feb 15 '07 #3
jasonchan
16 New Member
also for some reason, it work in IE6.0 at all... am i missing anything?
Feb 15 '07 #4
acoder
16,027 Recognized Expert Moderator MVP
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:
Expand|Select|Wrap|Line Numbers
  1. text-align:center;
Feb 15 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
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.
Feb 15 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
553
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 counter file $fp = fopen( $filename,"r"); // open it for READING ("r") $counter = fread($fp, filesize($filename) ); // read in value
9
9562
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). both files are in the /cgi/ folder
16
10633
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. There should never be any possibility of any number getting returned twice, or getting skipped over, even if f is being called from
6
4064
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 the user can change the date, which will force a requery in the subform to bring up records from the date selected. My question is this... The...
4
1407
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 and display in pictureboxes pcbCam1, pcbCam2, pcbCam4, pcbCam6, pcbCam7, and pcbCam8. So far the code works for one picture box not the others. Also...
3
10120
blackstormdragon
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 the store if she bought everything in the basket. The counter had a four-digit display, increment buttons for each digit, and a reset button. An...
9
2241
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. (i.e. "Addhandler application/x-httpd-php .html .php" in .htaccess). He says it is a security problem. Is it possible to make a PHP counter...
16
2079
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 to display one question and move to next question. Can someone please help me with the codes on coding "Next" button? Thanks -- Nejadian
5
2135
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 XML file that has been exported from an Access 2002 database. Upon MouseOver, my script calls the function getText(assetID) where "assetID" is a...
0
7751
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7992
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7840
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5396
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5119
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1973
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.