Click to See Complete Forum and Search --> : Table colour change


neil9999
11-24-2003, 12:46 PM
Hi,

I have this code:


<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<SCRIPT LANGUAGE="JavaScript1.2">
function setv(){
clr="1";
chngeclr();
}
function chngeclr(){
if(clr=="1"){aclr="blue"; clr="2"};
if(clr=="2"){aclr="red"; clr="1"};
document.getElementById('tble').bgColor=aclr;
setInterval("chngeclr()",1000);
}
</script>

</head>

<body bgcolor="#99FF33" vlink="#0000FF" onload="setv()">
<table border="0" align="center">
<tr>
<td width="0%" align="center>Bla bla bla</td>
</table>
<table border="0" width="100%" id="tble">
<tr>
<td width="100%" colspan="3" align="center">Bla Bla Bla</td>
</tr>
</table>

</body>

</html>

What is meant to happen is for the background colour of the second table to change between red and blue every second. How could I then change it so it changes the font colour instead?

Thanks,

Neil

pyro
11-24-2003, 12:55 PM
That's probably not a good idea... what about people with epilepsy? Even for the rest of use, it would be quite annoying.

neil9999
11-24-2003, 01:14 PM
That's a possibility, but eventually I'm going to have the change so smooth it wouldn't trigger an epileptic fit/get on people's nerves. First though I just want to get it working with two bold colours, then once I've got that working I'll make it go more smooth.

Thanks,

Neil

pyro
11-24-2003, 01:31 PM
I'm simply posting this so you can learn from it. Even with subtle changes, I would certainly think it would be annoying...

<script type="text/javascript">
clr = "1";
function chngeclr() {
if (clr == "1") {
aclr = "blue";
clr = "2";
}
else if (clr == "2") {
aclr = "red";
clr = "1";
}
document.getElementById('tble').style.color = aclr;
}
setInterval("chngeclr()",1000);
</script>

fredmv
11-24-2003, 02:04 PM
Slightly modified version of neil9999 and pyro's code:<script type="text/javascript">
//<![CDATA[
var flag = true;
function start()
{
flag = !flag;
document.getElementById('foo').style.color = (flag) ? 'red' : 'blue';
}
setInterval(start, 1000);
//]]>
</script><div id="foo">bar</div>

pyro
11-24-2003, 02:09 PM
Yeah, I was going to use the ternary operator, but wanted to keep it simple to understand... :)

fredmv
11-24-2003, 02:12 PM
I understand what you mean completely, if I were you I probably would've done the same thing. Other than the use of the conditional/ternary operator is the use of the boolean flag, which, I felt that was another good thing to add. I'm simply providing an alternative way of doing it. :D

neil9999
11-25-2003, 12:59 PM
Thanks for your help. Now I've got this.

<html>

<head>

<script type="text/javascript">
function setv(){
clr="1";
aclr="1"
chngeclr()
}
function chngeclr(){

if (clr=="1") {aclr="#FF0000"; clr="2";}
else if (clr=="2") {aclr="#FF3300"; clr="3";}
else if (clr=="3") {aclr="#FF6600"; clr="4";}
else if (clr=="4") {aclr="#FF9900"; clr="5";}
else if (clr=="5") {aclr="#FFCC00"; clr="6";}
else if (clr=="6") {aclr="#FFCC33"; clr="7";}
else if (clr=="7") {aclr="#FFCC00"; clr="8";}
else if (clr=="8") {aclr="#FF9900"; clr="9";}
else if (clr=="9") {aclr="#FF6600"; clr="1";}

document.getElementById('tble').style.color=aclr;
}
setInterval("chngeclr()",100);
</script>
</head>

<body bgcolor="#99FF33" vlink="#0000FF" onload="setv()">

<table border="0" width="100%">
<tr>
<td width="100%" colspan="3" align="center" id="tble">Bla Bla Bla</td>
</tr>
</table>

</body>

</html>

It work just fine in Netscape 7.1 and the preview mode in Frontpage 2000, but it doesn't work in IE 6.0. Any ideas why?

Thanks again,

Neil

pyro
11-25-2003, 01:14 PM
Works fine in IE 6 for me...

fredmv
11-26-2003, 01:20 AM
It works just fine for me too. I would imagine the internal browser in Frontpage is based on IE or is IE so it should have worked fine. Consider trying it again I suppose.

neil9999
11-26-2003, 11:05 AM
Just a mo - the code I gave you does work, it was the same as the version that didnt work but with most of the contents gone. I'll have to see if any of the contents of the table are affecting it.

Thanks,

Neil