FoxRocks Posted June 1, 2012 Share Posted June 1, 2012 Hello, Thank you for your interest in my problem. I have a basic php form using the table element consisting of over 50 rows and 4 columns. I have 2 check boxes associated with each row that, when checked, changes the background color of that row. One check box toggles red, the other yellow. I've managed to find out how to accomplish that task with the help of some internet searching as I am brand new (read: started yesterday) to the world of PHP. So. That form, when posted, goes to a table on the same page that displays the results. What I would like to do is have the row color that was selected on the form show up on the posted table. This is do not know how to do and I have been trying to self learn with a lot of failure so far...I'm hoping you can help Here is my script: function changeColor(){ if(document.inform.chk1.checked){ document.getElementById("tr1").style.backgroundColor="#FF0000" } else if(document.inform.chk2.checked){ document.getElementById("tr1").style.backgroundColor="#FFFF00" } else { document.getElementById("tr1").style.backgroundColor="white"} } Here is my form: <form action="index.php" method="post" name="inform"> <table cellpadding="2" cellspacing="0" border="2"> <tr class="font14white" align="center" style="background:#C0C0C0;"> <td id="cell1input"> Unit </td> <td id="cell2input"> Schedule </td> <td id="cell3input"> EMMA </td> <td id="cell4input"> Status </td> </tr> <tr id="tr1" name="tr1"> <td id="cell1input"> OEQ </td> <td id="cell2input"> <input type="text" name="OEQ_Sched" size="15" value="<?php echo $_POST["OEQ_Sched"]; ?>"></input> </td> <td id="cell3input"> <input type="text" name="OEQ_EMMA" size="8" value="<?php echo $_POST["OEQ_EMMA"]; ?>"></input> </td> <td id="cell4input"> <input type="checkbox" name="chk1" onclick="changeColor()"></input><font style="background-color:#FF0000;">RED</font><br> <input type="checkbox" name="chk2" onclick="changeColor()"></input><font style="background-color:#FFFF00;">YELLOW</font> </td> </tr> </table> </form> Here is my table: <table cellpadding="2" cellspacing="0" border="2"> <tr class=".font14black" align="center" style="background:#FFF;" height="18"> <td> Unit </td> <td> SCHEDULE </td> <td> EMMA </td> </tr> <tr> <td id="cell1display"> OEQ </td> <td id="cell2display"> <?php echo $_POST["OEQ_Sched"]; ?> </td> <td id="cell3display"> <?php echo $_POST["OEQ_EMMA"]; ?> </td> </tr> </table> Thank you for any help you can provide. ~FOX~ Quote Link to comment https://forums.phpfreaks.com/topic/263473-how-do-i-change-tr-background-color-using-checkbox-and-have-that-color-_post/ Share on other sites More sharing options...
requinix Posted June 1, 2012 Share Posted June 1, 2012 $_POST["chk1"] and $_POST["chk2"] are the two checkboxes you made. Specify the background color accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/263473-how-do-i-change-tr-background-color-using-checkbox-and-have-that-color-_post/#findComment-1350368 Share on other sites More sharing options...
nogray Posted June 1, 2012 Share Posted June 1, 2012 First, you would need to use a radio button since the user can only select one option and pass the object to the function because I assume you have more than on table row <input type="radio" value="#FF0000" onclick="changeColor(this);" name="Table_Row_1" /> <input type="radio" value="#FF0000" onclick="changeColor(this);" name="Table_Row_1" /> If your function, you can get the table row by looking up the parents node of the element function changeColor(obj){ var td = obj.parentNode; // table cell var tr = td.parentNode; // table row tr.style.backgroundColor = obj.value; // change the tr background color } NOT TESTED Quote Link to comment https://forums.phpfreaks.com/topic/263473-how-do-i-change-tr-background-color-using-checkbox-and-have-that-color-_post/#findComment-1350419 Share on other sites More sharing options...
FoxRocks Posted June 4, 2012 Author Share Posted June 4, 2012 Hello, Thanks for the replies, and I apologize for the tardy response, I'll be working on this project again today and I will definitely try these suggestions and get back to you. I think the idea of a radio button is the way to go. Thanks! ~FOX~ Quote Link to comment https://forums.phpfreaks.com/topic/263473-how-do-i-change-tr-background-color-using-checkbox-and-have-that-color-_post/#findComment-1350992 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.