First off I would like to say that I programmed a LONG time ago at school but I had alot of trouble getting into programming cause of ADD, so now I'm just 'trying' stuff at my own tempo with no pressure so I can pace it reall slow, but that does mean I'm a complete beginner, I know only snippets of some languages.
Now onto the problem, what I want to do eventually is change text color through a button click, so if I click a button with the label blue I want the text to turn blue and same with red etc.
So what I have is 2 buttons,
<button type="button" id="redButton" onclick="changeText()" value="red">Red</button>
<button type="button" id="blueButton" onclick="changeText()" value="blue">Blue</button>
Now in my javascript file I have the following:
var rButton = document.getElementById("redButton");
var bButton = document.getElementById("blueButton");
And I can alert both var with their value and it shows the value.
What I can't seem to figure is how to perhaps put rButton & bButton in a new var like
var cButton = [rButton, bButton];
Or something along those lines. Cause I can put cButton into an if statement right now and say this like:
if(cButton = document.getElementById("redButton"))
{
alert("Hello!");
}
else if(cButton = document.getElementById("blueButton"))
{
alert("Hello hello");
}
else
{
alert("Error!");
}
But that will only show Hello! and not Hello Hello even though I do press my blue button.
It's probably something realy stupid but I can't figure it out, and I haven't found much on google that I tried that worked.
Also yes changeText() is the function name which is where all this stuff is in.