I am creating a quiz application which contains two files:
question.php and process.php
In question.php
, the user enters his answer in a textbox and clicks a submit button which, by means of a form, has the input he provides processed in a process.php
file.
After processing the input, the process.php
file redirects the user to a new question.
Now the problem is that before redirecting the user to a new question I want the textbox to glow red if his answer is incorrect and green if correct.
However this obviously needs to be done in the javascript code of the question.php
file.
Since the user's input has been sent to the process.php file, I doubt that there is any way of referencing $_POST['answer']
in my question.php
's javascript.
In question.php I have the form:
<form method="post" action="process.php">
In question.php
I wish to alter the background color of the textbox according to the user's answer. This code is obviously wrong, but it should give you an idea of what I have in mind.
if(<?php echo $_POST['answer']; ?p> != correctAnswer)
document.getElementById('blankSpace').background-colour = red;
The only solution that I can think of is to have the form data submitted to both files. Is this possible?