...

View Full Version : checkboxes and cells. PLEASE HELP!



maltrecho
06-11-2003, 08:33 PM
I've got a problem, and I'm sure you could help me. I've got an attached file and everything is properly explained there. Please download it an check it. I would be very thankfull.
It's got to do with checkboxes and cells properties.

HERE IS THE CODE:

<html>
<head>
<title>THE PROBLEM !</title>

<script language="javascript" type="text/javascript">
<!--

// I THINK THERE SHOULD BE 2 VARIABLES, ONE FOR "CHECKBOX_" AND ANOTHER ONE FOR "TD_"
// BUT DON'T KNOW TOO MUCH ABOUT JAVASCRIPT...

function swapBG() {
if (document.form.checkbox_7.checked) {
document.getElementById("td_7").style.background='white';
} else {
document.getElementById("td_7").style.background='lightblue';
}
}
//-->
</script>

</head>
<body bgcolor="lightblue" onLoad="javascript:swapBG();">

<p>When the checkbox is checked, the background of the cell should be white, and when it is not checked, the background of the cell should be lightblue (like in the first cell). The problem is that I cannot give different names or identifiers to the CHECKBOXES an to the TDs because I don't know how many cells will be shown in the page (depending of the results given by a query). PHP will give a unique name or identifier to each CHECKBOX and TD, but I don't know how JavaScript could digest all this without previously knowing all the names and identifiers.</p>
<table width="100%" border="1" cellpadding="5" cellspacing="5">
<form name="form">
<tr>

<!-- THE NUMBERS ("1" "2" "53" "748"...) IN "TD_" AND "CHECKBOX_", WILL BE GIVEN
// BY PHP ACCORDING TO THE IDENTIFIER FOUND IN THE DATABASE AND WILL BE THE SAME NUMBER
// IN THE FOLLOWING 2 CASES //-->

<td id="td_7">
<div align="left">
<input type="checkbox" name="checkbox_7" checked onClick="javascript:swapBG();">
<b>CELL 1 (ok)</b>
</div>
</tr>
<tr>

<!-- AGAIN, THE NUMBERS ("1" "2" "53" "748"...) IN "TD_" AND "CHECKBOX_", WILL BE GIVEN
// BY PHP ACCORDING TO THE IDENTIFIER FOUND IN THE DATABASE AND WILL BE THE SAME NUMBER
// IN THE FOLLOWING 2 CASES //-->

<td id="td_284">
<div align="left">
<input type="checkbox" name="checkbox_284" checked onClick="javascript:swapBG()">
<b>CELL 2 (ouch!)</b>
</div>
</td>
</tr>

<!-- AGAIN, THE NUMBERS ("1" "2" "53" "748"...) IN "TD_" AND "CHECKBOX_", WILL BE GIVEN
// BY PHP ACCORDING TO THE IDENTIFIER FOUND IN THE DATABASE AND WILL BE THE SAME NUMBER
// IN THE FOLLOWING 2 CASES //-->

<tr>
<td id="td_36">
<div align="left">
<input type="checkbox" name="checkbox_36" checked onClick="javascript:swapBG()">
<b>CELL 2 (ouch!)</b>
</div>
</td>
</tr>
</form>
</table>
<p>Thanks in advanced</p>
</body>
</html>

cheesebagpipe
06-11-2003, 10:31 PM
<html>
<head>
<title>THE PROBLEM !</title>

<script language="javascript" type="text/javascript">
<!--

function swapBG(oCheckbox) {
var td = oCheckbox.parentNode.parentNode, bWhich = oCheckbox.checked;
td.style.background = (bWhich) ? 'white' : 'lightblue';
}

//-->
</script>
</head>
<body bgcolor="lightblue">
<table width="100%" border="1" cellpadding="5" cellspacing="5">
<form name="form">
<tr>
<td id="td_7" bgcolor="white">
<div align="left">
<input type="checkbox" name="checkbox_7" checked onclick="swapBG(this)">
<b>CELL 1 (ok)</b>
</div>
</tr>
<tr>
<td id="td_284" bgcolor="white">
<div align="left">
<input type="checkbox" name="checkbox_284" checked onclick="swapBG(this)">
<b>CELL 2 (ouch!)</b>
</div>
</td>
</tr>
<tr>
<td id="td_36" bgcolor="white">
<div align="left">
<input type="checkbox" name="checkbox_36" checked onclick="swapBG(this)">
<b>CELL 2 (ouch!)</b>
</div>
</td>
</tr>
</form>
</table>
<p>Thanks in advanced</p>
</body>
</html>

http://www.brainjar.com/dhtml/intro/

maltrecho
06-13-2003, 12:37 PM
Thanks, thanks, thanks !!!! and thanks again for the link.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum