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 3 of 3
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    35
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Change table background color with simple JS function

    Hi, I need some help writing a simple javascript function that allows me to change the background color of a table.
    http://dev.tommybaynard.com/sample_page2.php
    Thyanks for any help...
    Rich


    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Reach1000 sample</title>
    
    </head>
    
    <body>
    <p><a href="#">Change Table to Blue</a></p>
    <p><a href="#">Change table to red</a></p>
    <table width="500" height="500" border="0" cellpadding="20" cellspacing="0" bgcolor="#cccccc" id="myTable">
      <tr>
        <td><p>&nbsp;</p>
        </td>
      </tr>
    </table>
    
    </body>
    </html>

  • #2
    New Coder
    Join Date
    Jul 2008
    Location
    New York
    Posts
    24
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Arrow

    Try something like this:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Reach1000 sample</title>
    
    <style type='text/css'>
    
    #myTable {
    	width: 500px;
    	height: 500px;
    	background-color: #CCCCCC;
    	}
    
    </style>
    
    <script type='text/javascript'>
    
    function change(color) {
    	document.getElementById('myTable').style.backgroundColor = color;
    	}
    
    </script>
    
    </head>
    
    <body>
    <p><a href="javascript:void(0)" onclick="change('#003F87');">Change Table to Blue</a></p>
    <p><a href="javascript:void(0)" onclick="change('#FF3333');">Change table to red</a></p>
    
    <table cellpadding="20" cellspacing="0" id="myTable">
      <tr>
        <td><p>&nbsp;</p>
        </td>
      </tr>
    </table>
    
    
    
    </body>
    </html>

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    And why is this in the Ajax section?

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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