Hello,

Well I've got a bunch of Textboxes with color hex codes inside (#cccccc). Now in an IFrame on the same page I want to use these colors.
I couldn't find a solution yet, can somebody please help me.

Thanks in advance.

Recommended Answers

All 3 Replies

In javascript:
- You have to read the value from the text box.
- You have to make a string with the #rrggbb value in it.
- You have to assign the value so created to the style attribute needed.

Remember that the hyphenated form does not exist in javascript. So:

"background-color" in css, becomes
"backgroundColor" in JavaScript.

The following is an example of the form prgrss with object os3, and an array of color codes colox:

document.forms.prgrss.os3.style.backgroundColor = colox[cox];

Well lets say I have something like this:

<body bgcolor="doument.form.field.value;">

Why doesent it work?

What you wrote doesn't work because the html is rendered before those values exist.

HTML is a passive language. It renders once, then quits.

Also, the variable you are trying to read is not available to the body tag. A tag's attributes are defined only inside that tag.

And the syntax "document.form.field.value;" is JavaScript syntax, not html or css syntax.

And it works better if you can spell "document".

Finally, the bgcolor attribute is deprecated. It will not be supported in future web language.

You must use JavaScript (or a server-side script) to do any dynamic (changeable) content.

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.