Dynamically change in one PHP file when an action is encountered in another PHP file

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

The first PHP file is 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 color of the h4 element in the second PHP file (status.php).

Thank you for your guidance and help in advance.

+3


source to share


1 answer


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 it...

0


source







All Articles