faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

54 of 85 people (64%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I change the font color of a <tr> when a checkbox has been selected

Apr 5th, 2008 20:22
ha mo, Darton Williams, Ram kathir,


This is easy to do in IE, using something like the following:
<HEAD>
<STYLE type="text/css">
.test{color: green;}
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
function changeColor()
{
if(document.myForm.check1.checked==true)
	{
	document.getElementById('td1').style.color = 'red';
	document.getElementById('td1').innerText = 'Text is red when 
checked';
	}
else if(document.myForm.check1.checked==false)
	{
	document.getElementById('td1').style.color = 'green';
	document.getElementById('td1').innerText = 'Text is green 
again';
	}
}
</SCRIPT>
</HEAD>
<BODY>
<TABLE>
<TR>
<TD id="td1" class="test">
Text is green initially
</TD>
</TR>
</TABLE>
<FORM name="myForm">
<input type="checkbox" name="check1" onClick="changeColor()">Change 
Color
</FORM>
</BODY>
Netscape 4.x is an entirely different story, because of its horribly 
anemic CSS support. You'd probably have to use a layer and 
document.write to accomplish this simple task. It doesn't seem to be 
able to access the basic CSS properties of appearance (somebody please 
correct me if I'm wrong). Things look a lot better in NS6, but I'm not 
sure of the exact syntax to use for that.
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com