[Javascript] cross browser dhtml - text replacement
Matt Warden
mwarden at gmail.com
Fri Sep 3 16:27:08 CDT 2004
Hello, List.
I have a series of 4 spans. Each span holds a day, hour, minute, or
second value. And I am counting down the seconds. My script works in
mozilla/firefox, but apparently it doesn't work in anything else. I
have searched various sites, and they have some wonderful tutorials on
how to write cross-browser functions for this, as long as by "cross
browser" you mean nn4 and ie4. And they all use divs, not spans, which
would be less semantically appropriate for what I am doing.
Any thoughts?
Here's basically where the problem is:
var osec, omin, ohrs, oday;
if (document.getElementById)
{
osec = document.getElementById('secs');
omin = document.getElementById('mins');
ohrs = document.getElementById('hrs');
oday = document.getElementById('days');
}
else if (document.all)
{
osec = document.all['secs'];
omin = document.all['mins'];
ohrs = document.all['hrs'];
oday = document.all['days'];
}
else if (document.layers)
{
osec = document.layers['secs'];
omin = document.layers['mins'];
ohrs = document.layers['hrs'];
oday = document.layers['days'];
}
secs = (osec.innerHTML)-0;
mins = (omin.innerHTML)-0;
hrs = (ohrs.innerHTML)-0;
days = (oday.innerHTML)-0;
// ... snip snip ...
then I'm updating the value(s) like thus:
function setValue(o, v)
{
v = v-0;
if (v < 10) v='0'+v;
o.innerHTML = '';
o.innerHTML = v;
}
The setting innerHTML='' was an advised bug workaround.
Anything jump out at you as incorrect?
I also get a "osec has no properties" error in the JS console of
firefox, but it seems to have no negative effects on the script.
Thanks,
--
Matt Warden
Miami University
Oxford, OH
http://mattwarden.com
This email proudly and graciously contributes to entropy.
More information about the Javascript
mailing list