Closed Thread Icon

Topic awaiting preservation: Using "RGB(###,###,###) with variables?? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=24114" title="Pages that link to Topic awaiting preservation: Using &amp;quot;RGB(###,###,###) with variables?? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Using &quot;RGB(###,###,###) with variables?? <span class="small">(Page 1 of 1)</span>\

 
cicatriz
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Nov 2004

posted posted 11-19-2004 21:39

Hi, i'm quite new to javascript, and I have this poblem which is bummy and annoying.
I have created a 2 framed page, on the left is are three text boxes where a user enters values between 0-255.
The right side frame's background colour is changed once the user enters all the values and clicks the button.
Problem!... I use the following code.

function changeColour(colour){
redbox=colour.Red.value;
greenbox=colour.Green.value;
bluebox=colour.Blue.value;
parent.body.document.bgColor="rgb(redbox,greenbox,bluebox)";
}
when I run the programme and click the button it just chnages the right hand side to dark red, regardless of the values.
I know that the fucntion is retrieving the values from the text boxes as I tried adding
document.writeln(redbox); for example, and it would print the value entered in the red colour box.
What's going on with it? can anyone help me out?
P.S I tired adding ' and " marks around the variable names but it didnt change much, except with ' marks the colour changed to light blue regardless of the values entered.
Thanks, me.

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 11-19-2004 21:44

[überQuickReply]
hello and welcome in the Asylum,

you must output the redbox, greenbox and bluebox value, not there name, therefore you must replace :

code:
parent.body.document.bgColor="rgb(redbox,greenbox,bluebox)";

by

code:
parent.body.document.bgColor="rgb("+redbox+","+greenbox+","+bluebox+")";

Hope that helps...
[/überQuickReply]
Now, I can return to watch Alias

cicatriz
Obsessive-Compulsive (I) Inmate

From:
Insane since: Nov 2004

posted posted 11-20-2004 16:17

Yeah that worked great, thanks

cicatriz
Obsessive-Compulsive (I) Inmate

From:
Insane since: Nov 2004

posted posted 11-20-2004 17:51

Ok I have another problem
I want to make it so that the header text on the frame where the background colour changes, change colour to contrast with the bgcolour. I thought I could give the header an id and then use a long drawn out If, else if statement. But this seems too hard.
Is there anyway of getting the contrasting colours from rgb values?

liorean
Bipolar (III) Inmate

From: Umeå, Sweden
Insane since: Sep 2004

posted posted 11-20-2004 18:38

Cicatriz: Yes, it is possible. You'll have to do some math, though. What contrasting colour do you want - the inverse? The opposite hue at the same brightness?

--
var Liorean = {
prototype: HTMLGuru.prototype,
abode: "http://web-graphics.com/",
profile: "http://codingforums.com/member.php?u=5798"};

cicatriz
Obsessive-Compulsive (I) Inmate

From:
Insane since: Nov 2004

posted posted 11-21-2004 04:16

Yeah I want the opposite, so if the background was black the heading text would turn white.

liorean
Bipolar (III) Inmate

From: Umeå, Sweden
Insane since: Sep 2004

posted posted 11-21-2004 04:21

Then you just take 255-r, 255-g and 255-g. Simple as that. The same brightness/opposite hue thing is more difficult.

--
var Liorean = {
prototype: CSSGuru.prototype,
abode: "http://liorean.web-graphics.com/",
profile: "http://codingforums.com/member.php?u=5798"};

cicatriz
Obsessive-Compulsive (I) Inmate

From:
Insane since: Nov 2004

posted posted 11-21-2004 17:26

Ermmm, could you give me an example. I have
parent.body.document.bgColor="rgb("+redbox+","+greenbox+","+bluebox+")";
so i would write
parent.body.document.bgColor="rgb("+redbox-r","+greenbox-r","+bluebox-r")";
or something like that? I cant seem to figure it out

liorean
Bipolar (III) Inmate

From: Umeå, Sweden
Insane since: Sep 2004

posted posted 11-21-2004 19:15

parent.body.document.bgColor="rgb("+(255-redbox)+","+(255-greenbox)+","+(255-bluebox)+")";

--
var Liorean = {
prototype: XHTMLGuru.prototype,
abode: "http://liorean.web-graphics.com/",
profile: "http://codingforums.com/member.php?u=5798"};

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 11-21-2004 19:53

cicatriz: It'd be great if you tried some things by yourself before asking the solution.
We're not here to give you a fish, but to learn you how to fish.

DHTML/JavaScript and Javascript/DHTML are your friends. Use them, and abuse of them.

cicatriz
Obsessive-Compulsive (I) Inmate

From:
Insane since: Nov 2004

posted posted 11-21-2004 20:26

I did try it on my own, infact I spent several hours looking about on google before I finally decided to use a forum for your information

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 11-21-2004 21:34

cicatriz,

I think you're going to want to try something like:

code:
parent.body.document.bgColor="rgb("+redbox+","+greenbox+","+bluebox+")";
parent.body.document.color="rgb("+(255-redbox)+","+(255-greenbox)+","+(255-bluebox)+")";



To se the text color to the inverse of the background color. The problem with this method is that the closer to medium gray (127, 127, 127) you get the more the text and the background will look alike. But i'm sure once you get this working you can figure out how to handle that situation.

-- not necessarily stoned... just beautiful.

cicatriz
Obsessive-Compulsive (I) Inmate

From:
Insane since: Nov 2004

posted posted 11-22-2004 14:02

ok thanks guys, thats a big help.

« BackwardsOnwards »

Show Forum Drop Down Menu