SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Also available in Large Si's Avatar
    Join Date
    Sep 2002
    Location
    Walsall, UK
    Posts
    1,911
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Change BGcolor of table cell

    Hi All

    I'm trying to change the background colour of a table cell (or layer - wotever) according to the figure entered into a text input. The idea is for a user to type in a hexadecimal colour code (eg. #ffffff) and see a preview of that colour in a box. The box is currently defined by a small table but this could be anything. The code I've currently got is this:
    Code:
    <script language="JavaScript">
    <!--
    function updatePreview() {
    fgc = document.form1.fontcolour.value;
    document.getElementByID(prevFontColor).style.background = fgc;
    
    }
    -->
    </script>
    
    <input name="fontcolour" type="text" id="fontcolour" value="#000000" size="10" maxlength="7" onblur="updatePreview();">
    
    <table width="14" height="14" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
    <tr> 
    <td style="background-color: #000000" id="prevFontColor" width="12" height="12">
    <img width="12" height="12" border="1" alt="" src="../files/spacer.gif">
    </td>
    </tr>
    </table>
    Can anyone help?
    Cheers,
    Si
    Are you a Photoshop Jedi Master? Prove it!

    Is funky house your bag? You'll love this!

    Voice
    , eyes, ears, body and hands.


  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Change this line in your script:
    Code:
    document.getElementByID(prevFontColor).style.background = fgc;
    to this:
    Code:
    document.getElementByID("prevFontColor").style.backgroundColor = fgc;

  3. #3
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function updatePreview(fgc) {
    document.getElementById('prevFontColor').style.backgroundColor = fgc;
    ....

    <input onblur="updatePreview(this.value);">


    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  4. #4
    Also available in Large Si's Avatar
    Join Date
    Sep 2002
    Location
    Walsall, UK
    Posts
    1,911
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers lads - got it working now...
    Si
    Are you a Photoshop Jedi Master? Prove it!

    Is funky house your bag? You'll love this!

    Voice
    , eyes, ears, body and hands.



Bookmarks

Posting Permissions

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