3

I have two PHP files being shown to the user using frames. (Below is a small portion of the code from the two files)

First PHP file - q11.php

echo "<form action = 'q21.php' method = 'post' id = 'sub1'>";
    echo "<br><input type = 'submit' name = 'ans' value = 'a'>";
    echo "<br><input type = 'submit' name = 'ans' value = 'b'>";
    echo "<br><input type = 'submit' name = 'ans' value = 'c'>";
    echo "<br><input type = 'submit' name = 'ans' value = 'd'>";
echo "</form>";

Second PHP file - status.php

echo "<h4 id = 'q1'>Question 1";

Now, when the user clicks on any of the submit buttons belonging to the first PHP file (q11.php), I want to change the colour of the h4 element in the second PHP file (status.php).

Thank you for the guidance and help in advance.

anj28
  • 51
  • 6

1 Answers1

0

First Page

<form action = 'status.php' method = 'post' id = 'sub1'>
<input type = 'submit' name = 'ans' value = 'a'><br>
<input type = 'submit' name = 'ans' value = 'b'><br>
<input type = 'submit' name = 'ans' value = 'c'><br>
<input type = 'submit' name = 'ans' value = 'd'>
</form>

Second Page: status.php

<?php
if($_POST['ans'])
{
    $ans=$_POST['ans'];
    if($ans=='a')
    {
        $color='blue';
    }
    if($ans=='b')
    {
        $color='red';
    }
    if($ans=='c')
    {
        $color='green';
    }
    if($ans=='d')
    {
        $color='yellow';
    }
}
?>
<h4 id = 'q1' style="color:<?php echo $color; ?>">Question 1</h4>

Try this...

Edwin Thomas
  • 1,186
  • 2
  • 18
  • 31