Trying to create a ticker in javascript

T

Terry

I am trying to create a ticker that goes from 0 to 9, when hitting 9
resets to 0 and repeats. Unfortunately my attempt just hangs after
displaying "0" to the browser and alerting "1". Any suggestions would
be appreciated on how to do what I am trying to do.

the url to my page where I am doing this is:

http://theamazing.onlinewebshop.net


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<head>
<title>ticker</title>
<script type="text/javascript">
var x = 0;
var y = 1;
function ticker(){





document.write(x)
x = x +1;
if (x == 9)
x = 0;

alert("x = " + x);
}


</script>
</head>
<body>
<script type="text/javascript">




setInterval(function() { ticker.call(this); },1000);
</script>
</body>
</html>
 
T

Thomas 'PointedEars' Lahn

Terry said:
I am trying to create a ticker that goes from 0 to 9, when hitting 9
resets to 0 and repeats. Unfortunately my attempt just hangs after
displaying "0" to the browser and alerting "1". Any suggestions would
be appreciated on how to do what I am trying to do.

the url to my page where I am doing this is:

http://theamazing.onlinewebshop.net

It hangs because of you calling document.write() after the document was
fully loaded. That causes the document to be overwritten (in memory),
and the script for the timeout ceases to exists, while the required
document.close() call is missing.

Use DOM references or methods to modify the the attribute value or the
content of an element instead.


PointedEars
 
T

Terry

It hangs because of you calling document.write() after the document was
fully loaded. That causes the document to be overwritten (in memory),
and the script for the timeout ceases to exists, while the required
document.close() call is missing.

Use DOM references or methods to modify the the attribute value or the
content of an element instead.

PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann

If I understand you correctly, the content should be created before I
attempt to change the content through the DOM.

What I was going to try to do is emulate a digital clock using
javascript and CSS. I was going to have a series of divs represent
each portion of a digit. Changing the background color of the
particular divs would produce the effect of looking like a certain
number.

This is a little bit off topic but it possible to have images that
were once part of the div (perhaps as a background image) removed from
the div using DOM methods? Also, if it is possible will it be resource
intensive perhaps using more bandwith than should occur?
 
T

Thomas 'PointedEars' Lahn

Terry said:
Terry said:
I am trying to create a ticker that goes from 0 to 9, when hitting 9
resets to 0 and repeats. Unfortunately my attempt just hangs after
displaying "0" to the browser and alerting "1". Any suggestions would
be appreciated on how to do what I am trying to do.
the url to my page where I am doing this is:
http://theamazing.onlinewebshop.net
It hangs because of you calling document.write() after the document was
fully loaded. That causes the document to be overwritten (in memory),
and the script for the timeout ceases to exists, while the required
document.close() call is missing.

Use DOM references or methods to modify the the attribute value or the
content of an element instead.
[...]

Please trim your quotes, and don't quote signatures unless you are referring
to them. http://www.jibbering.com/faq/faq_notes/clj_posts.html
If I understand you correctly, the content should be created before I
attempt to change the content through the DOM.
Exactly.

What I was going to try to do is emulate a digital clock using
javascript and CSS. I was going to have a series of divs represent
each portion of a digit. Changing the background color of the
particular divs would produce the effect of looking like a certain
number.

I have written a test case for a countdown timer recently, which might
provide some insight:

http://PointedEars.de/scripts/test/dom/countdown
This is a little bit off topic

It isn't :)
but it possible to have images that were once part of the div
(perhaps as a background image) removed from the div using DOM
methods?

Yes, use

imgElemObjRef.parentNode.removeChild(imgElemObjRef);

to remove `img' elements. It would be prudent to give the `img' element a
name then, e.g.

<img src="..." alt="..." name="imgName">

so that it can be referred "cross-browser" with

var imgElemObjRef = document.images["imgName"];

For background images, use

elemObjRef.style.backgroundImage = "none".
Also, if it is possible will it be resource intensive perhaps using
more bandwith than should occur?

The only bandwidth that is used more would be when your source is
downloaded. That kind of DOM scripting runs client-side, so given
no further access to server resources, the only resources it takes
up are computing time and memory.


HTH

PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
What I was going to try to do is emulate a digital clock using
javascript and CSS. I was going to have a series of divs represent
each portion of a digit. Changing the background color of the
particular divs would produce the effect of looking like a certain
number.

You mean like in <URL:http://www.merlyn.demon.co.uk/$$7seg.htm>, the
counting digit ?

It's easy enough to structure a digit as a Table and use Javascript to
change the CSS styles each second. To avoid HTML repetition, multiple
digits could be constructed initially by script.


TL's code appears buggy in IE6; and in some systems will run slow.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
G

Gregor Kofler

Thomas 'PointedEars' Lahn meinte:
-v please

Upon clicking "Start":
Zeile: 767; Fehler: 'undefined' ist Null oder kein Objekt

The objectioned code:

if (typeof s != "string")
{
s = s.toString();
}

Gregor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top