Tom
Tom

Reputation: 317

Javascript passing parameters into function

Hey, i cant seem to get this to work, im a little confused on how im supposed to pass the colour paramaters:

function colourGreen(red, green, blue)
        {
            document.getElementById("button1").style.backgroundColor = 'rgb(red,green,blue)';
        }

............. .............

<input type="button" id = "button2" value="Price up" onclick = 'colourGreen(0,255,0)'>

Upvotes: 0

Views: 204

Answers (3)

Craig
Craig

Reputation: 7671

I'm guessing this should do the trick

function colourGreen(red, green, blue)
        {
            document.getElementById("button1").style.backgroundColor = 'rgb('+red+','+green+','+blue')';
        }

Upvotes: 3

John Weldon
John Weldon

Reputation: 40789

.style.backgroundColor = 'rgb(' + red +', ' + green + ', ' + blue ')';

Upvotes: 1

realshadow
realshadow

Reputation: 2585

...'rgb('+red+','+green+','+blue+')';

Upvotes: 1

Related Questions