Page 1 of 1

Checkbox to change the cell color when marked.

Posted: Sun Apr 22, 2012 3:01 pm
by roeio
Hey,

I have written a PHP code to parse my XML file using an array and a for loop and will set each and every value from the XML file to a varible and attached it to a new varible that builds everytime the script runs another line in table of the data parsed from the XML file.

for example my output is:

Host Name Uptime IP-Addr Status AC Notes [Click to Submit button]
ROY01 3hrs 42min 1.1.1.1 Backup ON [ ] Need to run maintinence at 09:00pm.

Now, the [] is the checkbox. I want to check the checkbox button and I want ONLY the notes cell to be colored in some kind of color.

How do I do that? Do I need to do that inside the for loop while parsing the XML file?

Example of how my PHP code is written

Code: Select all

<? php

$Filename=file.xml;
data=[];
$myfile= simplexml_load_file('$Filename');

<table syntax I cant remmber right now>

for loop parsing the xml.......... {
            $machine=$xml->machine;
            $uptime=$xml->uptime;
            ...
            ...
            $mynotes=$xml->notes;
$data=<div><th>$machine</th><th>$uptime</th>..............<th>$mynotes</th></div>
}

echo $data

</table>
?>
Thanks about the code... I want at the left of the "$mynotes" varible to have a check box and if I mark the checkbox and hit the "Click to submit" button then the cell of the specfic line (only the notes cell) turns yellow.

I thought about inserting a code that has a $color varible that stores the color varible name and if it is checked then the $color="yellow"

but I don't know how to validate if the checkbox is marked...

How can I do that?

Please Advise,
Roy.

Re: Checkbox to change the cell color when marked.

Posted: Sun Apr 22, 2012 7:02 pm
by requinix
Could you do us all a favor and just post your real code?

Re: Checkbox to change the cell color when marked.

Posted: Mon Apr 23, 2012 12:28 am
by roeio

Code: Select all

$data = "";
$filename = 'status.xml';
$xml = simplexml_load_file($filename);

// Header for the status page (Status page name and refresh time).
echo ('<HTML>'."\n".'<head>'."\n".'<link rel="STYLESHEET" href="http://14.10.10.1/ss/status.css" type="text/css"><meta http-equiv="refresh" content="60,url=status.php"/>'."\n".'<title>My status Page.</title>'."\n"."\n");
echo "</head>";

// Secondery table created and being built via XML parsing...

echo ('<table border = "1" bgcolor="#F5F5F5" cellspacing = "0"  cellpadding="0" align="center" width="100%">');

// MAIN LOOP STARTING

$f = fopen ( $filename, 'r' );
                 for ($i = 0; $i < 10; $i++){
                        $serverid= $xml->box[$i]->serverid;
                        $status= $xml->box[$i]->status;
                        $uptime= $xml->box[$i]->uptime;
                        $ac= $xml->box[$i]->ac;
                        $notes= $xml->box[$i]->notes;
                        
                        // Starting various conditions for TABLE Design.
                        if ($status == "Backup") {
                          $newstate ='<td bgcolor=#48D1CC align="center">'."<font color=black><B>".$status.'</B></td>';
                        }
                        elseif ($status== "Stopped") {
                          $newstate = '<td bgcolor=orangered align="center">'."<font color=white><B>".$status.'</B></td>';
                         }
                        elseif ($status== "Idle") {
                         $newstate = '<td bgcolor=Pink align="center">'."<font color=white><B>".$status.'</B></td>';
                        }
                        else {
                        $newstate="<td>$status</td>";
                        }
                        if ($serverid == null ) {
                        $serverid="----------";
                        }
   $data .= "<th>$serverid</th><th>$newstate</th><th>$uptime</th>$ac<th>$notes</th</tr></div>";

        echo ('<TR bgcolor=teal align="center">
        <th width="3%" bgcolor=teal><strong><font color=#FFFFFF>ServerID</font></strong></th>
        <th width="3%" bgcolor=teal><strong><font color=#FFFFFF>Status</font></strong></th>
        <th width="4%" bgcolor=teal><font color=#FFFFFF><strong>Uptime</strong></th>
        <th width="3%" padding="2" bgcolor=teal><font color=#FFFFFF><strong>AC State</strong></th>
        <th width="3%" bgcolor=teal><strong><font color=#FFFFFF>Notes</strong></th>
               <th width="17%" align=center bgcolor=teal><font color=#FFFFFF><form name="Notes" action="status.php" method="post">Time:&nbsp');
        echo date("Y-m-d H:i");
        echo ('&nbsp &nbsp &nbsp<input type="submit" value="Click to Submit Notes"></th>
        </tr></strong>');

// Printing out the data and closing the table.

        print $data;

echo "</table>";


?>
                                   


Re: Checkbox to change the cell color when marked.

Posted: Mon Apr 23, 2012 1:01 am
by requinix
I'm not 100% sure what you want, but if you wanted to color a cell if its checkbox is clicked then you could use JavaScript like

Code: Select all

<th><input type="checkbox" name="whatever" onclick="this.parentNode.style.backgroundColor=(this.checked ? 'yellow' : '');" /></th>