944,072 Members | Top Members by Rank

Ad:
Aug 8th, 2007
0

Problem with applying colors from form

Expand Post »
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.
Last edited by sted; Aug 8th, 2007 at 6:14 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sted is offline Offline
2 posts
since Aug 2007
Aug 8th, 2007
0

Re: Problem with applying colors from form

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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. document.forms.prgrss.os3.style.backgroundColor = colox[cox];
Last edited by MidiMagic; Aug 8th, 2007 at 7:52 pm.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007
Aug 8th, 2007
0

Re: Problem with applying colors from form

Well lets say I have something like this:

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

Why doesent it work?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sted is offline Offline
2 posts
since Aug 2007
Aug 8th, 2007
0

Re: Problem with applying colors from form

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.
Last edited by MidiMagic; Aug 8th, 2007 at 9:47 pm.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: image gallery help
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: How do you read radio buttons in XHTML





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC