asmega
12-21-2003, 02:11 PM
ok heres the problem
the page has several checkboxes each in its own table in its own cell.
when the page LOADS i would like the colour of the cell the checkbox is in to depend on the status of the checkbox.
For example if the checkbox is not checked then the cell will be green if it is checked then the cell will be red. the status of the checkbox will be from a database and php will say whether the box is checked or not.
i believe something on the lines of this is needed however if your style different or you are not happy the please re-code the below
NOTE : THE CODE BELOW DOES NOT WORK
<script type="text/javascript">
//<![CDATA[
onload = function()
{
for(i=0; i<document.getElementsByTagName('input'); i++)
{
if(document.getElementsByTagName('input')[i].type == 'checkbox')
{
var c = document.getElementsByTagName('input')[i];
c.parentNode.parentNode.style.backgroundColor = (c.checked) ? '#f00' : '#090';
}
}
}
//]]>
</script>
NOTE : THE CODE ABOVE DOES NOT WORK
i would like the same thing to happen for onclick
<input type="checkbox" onclick="parentNode.parentNode.style.backgroundColor = (checked) ? '#f00' : '#090';" />
i belive that the above is needed to do this and the code above DOES work.
i hope this is clear as my javascript knowledge is limited
the page has several checkboxes each in its own table in its own cell.
when the page LOADS i would like the colour of the cell the checkbox is in to depend on the status of the checkbox.
For example if the checkbox is not checked then the cell will be green if it is checked then the cell will be red. the status of the checkbox will be from a database and php will say whether the box is checked or not.
i believe something on the lines of this is needed however if your style different or you are not happy the please re-code the below
NOTE : THE CODE BELOW DOES NOT WORK
<script type="text/javascript">
//<![CDATA[
onload = function()
{
for(i=0; i<document.getElementsByTagName('input'); i++)
{
if(document.getElementsByTagName('input')[i].type == 'checkbox')
{
var c = document.getElementsByTagName('input')[i];
c.parentNode.parentNode.style.backgroundColor = (c.checked) ? '#f00' : '#090';
}
}
}
//]]>
</script>
NOTE : THE CODE ABOVE DOES NOT WORK
i would like the same thing to happen for onclick
<input type="checkbox" onclick="parentNode.parentNode.style.backgroundColor = (checked) ? '#f00' : '#090';" />
i belive that the above is needed to do this and the code above DOES work.
i hope this is clear as my javascript knowledge is limited