hello there

i have some problem with rgb. i am writing a color selector , 3 sliders demonstrate 3 color , red and green and blue , then the mix color appears in a div named 'result' in the end of page. consider i have 3 variables which indicates 3 magnitude for r , g , and b. and this is my code :

document.getElementById("result").style.backgroundColor = 'rgb(r,g,b)'

but this is not working at all, and when i use below code ,instead of the above one , it is working :

document.getElementById("result").style.backgroundColor = 'rgb(10,10,10)'

but be sure that r and g abd b variables are all correct. because i use 'alert' function and all of them store a number between 0 and 255. i wonder if javascript does not compile the code between ' and ' , i mean rgb function , and pass the function to another program like html to compile, and html has no clue on r and g and b variables. am i right? is there any way to help me?

Recommended Answers

All 2 Replies

if you put the whole thing in ' ' , it will be treated as string literal, you should have to concatenate the string literals and the variables as follows:
'rbg(' + r + ',' + g + ',' + b + ')';

commented: simply gud... +2

thanks so much , it seems working

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.