Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #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.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 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\">&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.

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    color='#123abc'

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

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

    or just about any element

    see
    Drop Down Inputs into Text input box

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    aero space beat me to it
    Last edited by vwphillips; 06-03-2005 at 09:33 PM.

  • #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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •