I am trying to create a math question set for a website where the user will be given an equation and they have to write the answer in the form.
My HTML mark up looks like this
<p> Please write the sum of these two numbers </p>
<label for="num1">Number1: <?php echo rand(2,200)?>
<label for="num2">Number2: <?php echo rand(2,200)?>
<input name="sum" type="text" />
I want to be able to check if the entered the right sum of the two values that are generated. This is just generic at the point. It will eventually end up having more variables and different math operators for the question
How do I do the following with PHP server side script:
a) The value that the Label’s have from echo rand() function and
b) how do I get the code to store them as variables and output to the screen?
PS: I have to do it on php side and I am aware this might be do-able with Javascript/Jquery.
Thank you in advance for your help.
Varun
Javascript aside, you can’t access anything to do with the
<label>, the easiest way (aside from using session data) is to use an<input>.You’ll want to declare the value once, so you don’t get a different value displayed to the user than what is stored in the input. Quick example: