Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing <td bgcolor> using onclick. 1

Status
Not open for further replies.

FateFirst

Programmer
Apr 15, 2002
212
GB
hi!

I have a table:

Code:
<table>
<tr>
	<td id="bkg01" bgcolor="#008000"><img src="./images/spacer" border="0"></td>
</tr>
<table>

Now I want a series of <a>'s which I can click that change the bgcolor of this <td> cell above.

Any ideas how I go about this?

- FateFirst
 
Use something similar to this to get you started:
Code:
<script language=JavaScript>
function changeColor(newColor) {
   document.getElementById("bkg01").style.backgroundColor = newColor;
}
</script>
<body>
<form name=blahForm>
<a href="javascript:void(changeColor('#ffffff'))">White</a><br>
<a href="javascript:void(changeColor('#000000'))">Black</a><br>
<a href="javascript:void(changeColor('#ff0000'))">Red</a><br>
<a href="javascript:void(changeColor('#00ff00'))">Green</a><br>
<a href="javascript:void(changeColor('#0000ff'))">Blue</a><br>
<table>
<tr>
    <td id="bkg01" bgcolor="#008000">This is a table test</td>
</tr>
<table>
</form>
</body>

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top