...

View Full Version : Change table background color with simple JS function



reach100
08-11-2008, 10:38 PM
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



<!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>

tnowalk
08-12-2008, 03:54 AM
Try something like this:


<!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>

A1ien51
08-12-2008, 03:08 PM
And why is this in the Ajax section?

Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum