Here is the Aim of my Program.
- I Want around 5-6 Circles to be shown on the page, of colors red and green.
- When, any of the circle is clicked. Its color changes to BLUE.
- Then, if i click any other circle on the page its color should also change to BLUE, and the circle previously clicked should also show as BLUE.
- So, if i click all circles one by one, in succesive pageloads, all the circles should show up as blue.
- And, when a blue circle is clicked, it should show its original color.
- This loop should continue for-ever, until the page is closed.
This is what i have done till now.
define("SIZE", 5); //the no. of circles
class redblock
{
var $color;
function set_color($data)
{
$this->color = $data;
}
function get_color()
{
return $this->color;
}
function image_source()
{
$rval2 = $this->get_color();
echo $rval2;
}
function display_block()
{
$rval = $this->get_color();
echo "<img src = '",$rval,"' width=120> </br> " ;
}
}
for ($i=0 ; $i < SIZE ; $i++ ) //INIT color blocks
{ $rb[$i] = new redblock ; }
for ($i=0 ; $i < SIZE ; $i++ ) //color set
{
if(!isset($_POST[$i.'form']))
{
if ($i % 2 == 0) //even blocks are green
$rb[$i]->set_color("green.jpg");
else //odd blocks are red
$rb[$i]->set_color("red.jpg");
}
if ( $_POST[$i.'form'] == "blue.jpg" )
$rb[$i]->set_color("blue.jpg");
if(isset($_POST[$i.'form']))
$rb[$i]->set_color("blue.jpg");
} ?>
<?php
// BOTH BLOCKS when clicked repeatedly should turn to white and fro.
for ($i=0 ; $i < SIZE ; $i++ ) //display the blocks
{
echo "<form method ='post'>";
echo "<input type = 'image' width='120' src ='",$rb[$i]->image_source(),"'>";
echo "<input type='hidden' name='".$i,"form' value='",$rb[$i]-get_color(),"'>";
echo "</form>";
}
?>
What Happens, in this code. 1. Suppose, i click Circle 1. It turns to blue. 2. Then i click circle 2, it turns blue, but circle 1 becomes green again. I want circle one to retain the blue color.
Please give me the correct code, or guide me in the right direction. Even, a small help will be largely appreciated.
I have no knowledge of Javascript, etc. I only know PHP and HTML/CSS.
Thank you.