Enjoy an ad free experience by logging in. Not a member yet?
Register .
06-03-2005, 09:17 PM
PM User |
#1
Regular Coder
Join Date: May 2005
Posts: 262
Thanks: 4
Thanked 0 Times in 0 Posts
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.
06-03-2005, 09:23 PM
PM User |
#2
Supreme Master coder!
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
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\"> </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.
06-03-2005, 09:28 PM
PM User |
#3
Senior Coder
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,355
Thanks: 3
Thanked 458 Times in 445 Posts
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
06-03-2005, 09:31 PM
PM User |
#4
Senior Coder
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,355
Thanks: 3
Thanked 458 Times in 445 Posts
aero space beat me to it
Last edited by vwphillips; 06-03-2005 at 09:33 PM ..
06-03-2005, 09:31 PM
PM User |
#5
Regular Coder
Join Date: May 2005
Posts: 262
Thanks: 4
Thanked 0 Times in 0 Posts
Thanks _Aerospace_Eng_
Last edited by tripwater; 06-03-2005 at 09:34 PM ..
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 04:53 PM .
Advertisement
Log in to turn off these ads.