Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] [OT] Looking for Javascript 3-toggle button



On Mon, 15 Feb 2010 00:52:29 +0900, Dave M G <dave@example.com> wrote:

> Any idea what's missing?

You've also done completely away with referencing the control that's
actually been clicked on.

In the onclick method of the button, you're passing the id of the button
itself ("radar") to the buttonClicked() function. Within that function, the
control is referred to as "threestate", yet you're explicitly referring to
"radar" within the function. This means that, if you have multiple
instances of your three-state control in the page, whenever you click on
any one of them it's "radar" that's going to be altered.

Change the line within your function so that it grabs the elementById of
the button that's passed to it in its arguments:

var ctrl = document.getElementById(threestate);

Also, another thing I've just thought of that will need doing if there are
multiple controls like this one is that each one will need its own array of
backgrounds otherwise each click will cycle through the backgrounds instead
of it happening independently for each control.

Change the definition of the array to:

var images = new Array();
images['radar'] = new Array( "yellow", "red", "green" );

And change the buttonClicked() function so that it goes like this:

var newimage = images[threestate].shift();
images[threestate].push(newimage);
var ctrl = document.getElementById(threestate);
ctrl.style.backgroundImage = newimage + ".png";

-- 
G. Stewart - gstewart@example.com

Never let your schooling interfere with your education!

Attachment: pgpAQwc68BKWD.pgp
Description: PGP signature


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links