View Full Version : Color td background if checkbox inside it is checked.
ventura
04-30-2003, 10:54 PM
how can i color the background of a <td> if the checkbox inside it is checked?
i'm dynamically checking a checkbox based on the value from a database and if the checkbox is initially checked, i want the background of that td to be red.
chrismiceli
05-01-2003, 03:12 AM
javascript can do what I think you want
<input type="checkbox" onChange="document.tablename.tdname.bgcolor='red'">
cheesebagpipe
05-01-2003, 06:37 AM
Added a flip routine, if you need it...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>untitled</title>
<style type="text/css">
input.offbox {
background: green;
}
input.onbox {
background: red;
}
</style>
<script type="text/javascript" language="javascript">
function toggle(oCheckbox) {
var bWhich = oCheckbox.checked;
oCheckbox.className = (bWhich) ? 'onbox' : 'offbox';
}
var all_inputs = document.getElementsByTagName('input');
onload = function() {
var el, i = 0;
while (el = all_inputs.item(i++))
if (el.type == 'checkbox' && el.checked) el.className = 'onbox';
}
</script>
</head>
<body>
<form>
<input type="checkbox" class="offbox" onclick="toggle(this)" /><br />
<input type="checkbox" class="offbox" onclick="toggle(this)" /><br />
<input type="checkbox" class="offbox" onclick="toggle(this)" checked="checked" />
</form>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.