Jump to content

Dropdown box populating the bgcolour of a table


d0nski

Recommended Posts

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>

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.