d0nski Posted June 2, 2011 Share Posted June 2, 2011 Hi, Can someone help me with the following problem... I am populating a html table with results from a mysql query. These results populate the 1st of four columns. The second column is a "RAG STATUS" dropdown menu - so GREEN/AMBER/RED. When this is selected I want it to change the colour of the corresponding row it is on. I have had a play around but can only get it to change the colour of the first row, no matter which dropdown menu I change. Code is below. If anything is not clear please let me know. Any help appreciated <?php include ("commonTop.php"); include("dbvariables.php"); include("functions.php"); ?> <script type="text/javascript"> function changeBGCol(status) { document.getElementById("colour").bgColor=status; } </script> <?php $Checkout_ID = 2; $result = mysql_query( "SELECT Task FROM Task T, Checkout C Where T.Checkout_ID = C.Checkout_ID and C.Checkout_ID= $Checkout_ID" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); echo "This will be sent to the following recepients $num_rows records.<P>"; echo "<table width=70% border=3>\n"; echo "<tr><th>Check</th><th>STATUS</th><th>JIRA</th><th>Comments</th></tr>"; while ($get_info = mysql_fetch_row($result)){ echo "<tr id=colour>\n"; foreach ($get_info as $field) echo "\t<td><font face=arial size=1/>$field</font></td>\n"; echo "\t<td><select name='Status'> <option value='None'>-- Choose --</option> <option onclick='changeBGCol(this.value)' value='green' >GREEN</option> <option onclick='changeBGCol(this.value)' value='orange'>AMBER</option> <option onclick='changeBGCol(this.value)' value='red'> RED</option> </select></td>"; echo "\t<td><input type='text' name='JIRA'></td>"; echo "\t<td><input type='text' name='Comments'></td>"; echo "</tr>\n"; } print "</table>\n"; ?> [code] </code> Quote Link to comment https://forums.phpfreaks.com/topic/238220-dropdown-box-populating-the-bgcolour-of-a-table/ Share on other sites More sharing options...
dougjohnson Posted June 2, 2011 Share Posted June 2, 2011 This javascript function might work? I haven't tested it. It may not work inside the "options" tag"? <script type="text/javascript"> function changeBGCol(obj, color) { obj.style.backgroundColor=color } </script> Quote Link to comment https://forums.phpfreaks.com/topic/238220-dropdown-box-populating-the-bgcolour-of-a-table/#findComment-1224165 Share on other sites More sharing options...
d0nski Posted June 2, 2011 Author Share Posted June 2, 2011 Thanks but that doesn't work. It doesn't colour any of the rows... Quote Link to comment https://forums.phpfreaks.com/topic/238220-dropdown-box-populating-the-bgcolour-of-a-table/#findComment-1224177 Share on other sites More sharing options...
d0nski Posted June 2, 2011 Author Share Posted June 2, 2011 Anybody else have any other suggestions? Even a link to something similar? Quote Link to comment https://forums.phpfreaks.com/topic/238220-dropdown-box-populating-the-bgcolour-of-a-table/#findComment-1224303 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.