Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-03-2005, 09:17 PM   PM User | #1
tripwater
Regular Coder

 
Join Date: May 2005
Posts: 262
Thanks: 4
Thanked 0 Times in 0 Posts
tripwater is an unknown quantity at this point
Color Function help

I have a image of web color swatches. I am using mapping to tell my form what color they want. Example

Code:
<SCRIPT LANGUAGE=\"JavaScript\" type=\"text/javascript\">
function color_is_(cvalue)
{
document.addnotetype.color.value = cvalue;
}
</script>


<MAP NAME=\"spmap\">

<AREA SHAPE=\"RECT\" COORDS=\"1,1,7,10\" HREF=\"JavaScript:color_is_('#00FF00')\">
<AREA SHAPE=\"RECT\" COORDS=\"9,1,15,10\" HREF=\"JavaScript:color_is_('#00FF33')\">
<AREA SHAPE=\"RECT\" COORDS=\"17,1,23,10\" HREF=\"JavaScript:color_is_('#00FF66')\">
<AREA SHAPE=\"RECT\" COORDS=\"25,1,31,10\" HREF=\"JavaScript:color_is_('#00FF99')\">
<AREA SHAPE=\"RECT\" COORDS=\"33,1,39,10\" HREF=\"JavaScript:color_is_('#00FFCC')\">
<AREA SHAPE=\"RECT\" COORDS=\"41,1,47,10\" HREF=\"JavaScript:color_is_('#00FFFF')\">

</map>

<form name=\"addnotetype\">
<table>
<TR>
 <TD>
Click a color below to assign a highlight color.<br>
<IMG SRC=\"../images/color_chart.gif\" BORDER=0 WIDTH=289 HEIGHT=67 USEMAP=\"#spmap\">
</TD>
<td>

Highlight Color<br>
<input type=text size=7 maxlength=7 name=color value=\"\">
</td>
</TR>
</table>
</form>
Everything I have here works fine. When you click a color it passes the hexidecimal color to my form field. But what I would like to do is in another data cell, actually change its BG color to what they clicked so they can see it on the page. How do I do this?

Thank you for any help with this.
tripwater is offline   Reply With Quote
Old 06-03-2005, 09:23 PM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Code:
<SCRIPT LANGUAGE=\"JavaScript\" type=\"text/javascript\">
function color_is_(cvalue)
{
document.addnotetype.color.value = cvalue;
document.getElementById('thecolor').style.background=cvalue;
}
</script>


<MAP NAME=\"spmap\">

<AREA SHAPE=\"RECT\" COORDS=\"1,1,7,10\" HREF=\"javascript:color_is_('#00FF00')\">
<AREA SHAPE=\"RECT\" COORDS=\"9,1,15,10\" HREF=\"javascript:color_is_('#00FF33')\">
<AREA SHAPE=\"RECT\" COORDS=\"17,1,23,10\" HREF=\"javascript:color_is_('#00FF66')\">
<AREA SHAPE=\"RECT\" COORDS=\"25,1,31,10\" HREF=\"javascript:color_is_('#00FF99')\">
<AREA SHAPE=\"RECT\" COORDS=\"33,1,39,10\" HREF=\"javascript:color_is_('#00FFCC')\">
<AREA SHAPE=\"RECT\" COORDS=\"41,1,47,10\" HREF=\"javascript:color_is_('#00FFFF')\">

</map>

<form name=\"addnotetype\">
<table>
<TR>
 <TD>
Click a color below to assign a highlight color.<br>
<IMG SRC=\"../images/color_chart.gif\" BORDER=0 WIDTH=289 HEIGHT=67 USEMAP=\"#spmap\">
</TD>
<td>

Highlight Color<br>
<input type=text size=7 maxlength=7 name=color value=\"\">

</td>
</TR>
<tr>
<td style=\"width:50px;height:50px;\" id=\"thecolor\">&nbsp;</td>
</tr>
</table>
</form>
From the looks of your code, you must be echoing some php. You do know you don't have to echo html, as it will get parsed as html without using echo, unless you are checking for something in particular.
_Aerospace_Eng_ is offline   Reply With Quote
Old 06-03-2005, 09:28 PM   PM User | #3
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,355
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
color='#123abc'

document.getElementBtId('myid').style.backgroundColor=color;

<input id="myid" size=2 type="text" >

or just about any element

see
http://www.codingforums.com/showthread.php?t=60175
vwphillips is offline   Reply With Quote
Old 06-03-2005, 09:31 PM   PM User | #4
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,355
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
aero space beat me to it

Last edited by vwphillips; 06-03-2005 at 09:33 PM..
vwphillips is offline   Reply With Quote
Old 06-03-2005, 09:31 PM   PM User | #5
tripwater
Regular Coder

 
Join Date: May 2005
Posts: 262
Thanks: 4
Thanked 0 Times in 0 Posts
tripwater is an unknown quantity at this point
Thanks _Aerospace_Eng_

Last edited by tripwater; 06-03-2005 at 09:34 PM..
tripwater is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:53 PM.


Advertisement
Log in to turn off these ads.