Mailing List Archive


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

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



Godwin,

Thank you so much for the code!

I guess it is a small and trivial matter, but I'm still very much in the
copy-and-paste stage of using Javascript, so for me it's a huge leap
forward.

The code as provided didn't work right away, so I tried to modify it a
bit, and also customize it, but I'm not sure what is holding it back.

Some of the changes I made beyond changing some names was: there was a
comma where a period should be, I changed the switcher to use images
instead of colours, and I moved the Javascript to be in a separate file.

Here is the Javascript part as it now is:

var images = new Array( "green.png",
                        "yellow.png",
                        "red.png");

(function buttonClicked(threestate) {
    var newimage = images.shift();
    images.push(newimage);
    var ctrl = document.getElementById(radar);
    button.styles.backgroundImage = newimage;
})();

And here it is in the HTML (extraneous HTML ommitted):

<head>
    <script type="text/javascript"
src="javascript/button_3_stage.js"></script>
</head>

<input type="button"
            id="radar"
            onclick="buttonclicked('threestate')"
            style="background-image:
url(images/green.png);width:53px;height:53px;border:0;"
            value="" />

I use Firebug to debug Javascript, and it's saying:

radar is not defined
buttonClicked(Object { name="threestate"})button_3_stage.js (line 12)
button_3_stage.js()button_3_stage.js (line 9)
var ctrl = document.getElementById(radar);


I thought I defined "radar" because that is the ID of the button...? Am
I mixed up about how the Javascript identifies which button to use?

Thank you for any advice.

-- 
Dave M G


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links