Forum Moderators: open

Message Too Old, No Replies

Hiding checkboxes-modifying script

         

slanton

2:41 am on Jul 5, 2006 (gmt 0)

10+ Year Member



I have some javascript that in conjunction with some CSS hides checkboxes and also toggles the background colour of the surrounding table cell depending on whether or not the checkbox is checked ie unchecked = green, checked = orange. I have been trying to modify the code so that when the page loads if a checkbox is checked the cell will stay orange. Can anyone help?
The code is

<!-- hide checkboxes
// set checkboxes to "display:none;"
document.getElementsByTagName('html')[0]
.className = 'scriptDisabled';
function toggleBox(cell) {
var box = cell.getElementsByTagName('input')[0];
// Toggle check & get new state
var doCheck = (box.checked=!box.checked);
// empty --> green (via sheet)
cell.style.backgroundColor = doCheck? 'orange' : ''; }

and the CSS is

.scriptDisabled .chkCell input { visibility: hidden; position: absolute;left: -9000px;}
.chkCell{background: green;}

and it is called by

<td class='chkCell' onclick=\"toggleBox(this)\">

adni18

12:45 am on Jul 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<!-- hide checkboxes
// set checkboxes to "display:none;"
document.getElementsByTagName('html')[0].className = 'scriptDisabled';
function toggleBox(cell) {
var box = cell.getElementsByTagName('input')[0];

// Toggle check & get new state

var doCheck = (box.checked=!box.checked);

// empty --> green (via sheet)

cell.style.backgroundColor = doCheck? 'orange' : '';

}

....

.scriptDisabled .chkCell input { visibility: hidden; position: absolute;left: -9000px;}
.chkCell{background: green;}

....

<td class='chkCell' id='myTD' onclick=\"toggleBox(this)\">

....

toggleBox(document.getElementById("myTD"));
toggleBox(document.getElementById("myTD"));

Try that. It's a lazy man's way, but it should work.

slanton

2:13 am on Jul 6, 2006 (gmt 0)

10+ Year Member



Thanks