/    Sign up×
Community /Pin to ProfileBookmark

Flashing cell background color

I know… I know… dont cringe, when you hear ‘flashing’ or blinking. There is a valid reason to need specific cells in my table to flash. That being said…

I need several cells, which I will choose, to flash their background color, back and forth. I found the following solution online:

pmBox.bgColor=’#FFFFFF’;
setInterval(“Timer()”, 300);
x=1;
function Timer() {
set=1;
if(x==0 && set==1) {
pmBox.bgColor=’#FFCC00′;
x=1;
set=0;
}
if(x==1 && set==1) {
pmBox.bgColor=’#FF6600′;
x=0;
set=0;
}
}

The script is then called by setting the TD’s id: (<td id=”pmBox”>)

However, this won’t work for multiple cells, since they cannot have the same ID. Any ideas on how to modify this so it can be used on several cells?

Thanks in advance, JS is not really my thing. I’m spending too much time trying to pick up PHP

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinJan 19.2006 — give them all the same id + a number 0 to whatever

that will create an element list which you can loop through

by the way?

do you know how many flashes per second it takes to set off a photo-epileptic attack?

just something to bear in mind.
Copy linkTweet thisAlerts:
@touchmediaauthorJan 19.2006 — no worries, if I pull this off, you'll only see a 1 pixel border around the images flashing. Its a way to show search results... anyway... no laughing, because as I admitted, Im no JS Junkie, but I'm having trouble wrapping my head around the theory involved with your answer, and how to implement it.

Here's what I came up with (it doesn't work, obviously)

thanks again for your help



<td id="pm0"><img src="adphotos/thumbs/1.jpg"></td>

.......

<script language="JavaScript">

<!-- Begin

doo[0]="pm0";

doo[1]="pm1";

doo[2]="pm2";

doo[3]="pm3";

var x=0;

for (x=0; x<3; x++)

{

doo[x].bgColor='#FFFFFF';

setInterval("Timer()", 300);

x=1;

function Timer() {

set=1;

if(x==0 && set==1) {

doo[x].bgColor='#FFCC00';

x=1;

set=0;

}

if(x==1 && set==1) {

doo[x].bgColor='#FF6600';

x=0;

set=0;

}

}

}


// End -->

</script>
Copy linkTweet thisAlerts:
@CrazyMerlinJan 19.2006 — when you declare your 'for' statement you are evaluating x<3, but inside it you set x=1

so the loop will never evaluate and will run non-stop
Copy linkTweet thisAlerts:
@CrazyMerlinJan 19.2006 — not sure where you got the code from, but it's terrible

if(x==0 && isSet==1) {

doo[x].setAttribute('bgColor','#FFCC00');

x=1;

isSet=0;

}

if(x==1 && isSet==1) {

doo[x].setAttribute('bgColor','#FF6600');

x=0;

isSet=0;

}

will constantly keep setting the first row to one color and the second row to a different color, but they do not alternate.

Look at this in IE and tell me if this is what you are trying to achieve, but with multiple borders flashing...
[CODE]
<html>
<head>
<title></title>

<script language="JavaScript">

function Timer() {
isSet=1;
if(x==0 && isSet==1) {
doo[x].setAttribute('borderColor','#FFCC00');
x=1;
isSet=0;
}
if(x==1 && isSet==1) {
doo[x-1].setAttribute('borderColor','#FF6600');
x=0;
isSet=0;
}
}

</script>

</head>
<body>
<table border="1">
<tr id="pm0"><td>Some text in here -- flashing border</td></tr>
<tr id="pm1"><td>Some text in here -- flashing border</td></tr>
<tr id="pm2"><td>Some text in here -- flashing border</td></tr>
<tr id="pm3"><td>Some text in here -- flashing border</td></tr>
</table>

<script language="JavaScript">
var isSet=0;
var doo = new Array();
doo[0]=document.getElementById('pm0').firstChild;
doo[1]=document.getElementById('pm1').firstChild;
doo[2]=document.getElementById('pm2').firstChild;
doo[3]=document.getElementById('pm3').firstChild;


for(var x=0; x<3; x++){
doo[x].setAttribute('bgColor','#FFFFFF');
setInterval("Timer()", 300);
};
x=1;
</script>

</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@touchmediaauthorJan 19.2006 — Crazy, you're the man. This works, but I was hoping to have multiple cells flash at the same time, to highlght specific cell contents.

thanks for your help thus far by the way
×

Success!

Help @touchmedia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...