I've written the following code which records whether user submitted answers are correct. score_one is either 0 or 1 for getting the first question right, score_two is either 0 or 1 for getting the second question right and so on. totalScore is basically the sum of score_one to score_four
What I would like is that the totalScore value returned through PHP to my email address. My current HTML form has an email field and a name field. I have a PHP script which is successfully sending these field answers to my inbox. However I can't get the totalScore value to appear. The code below is what I'm using but I'm not an expert
<input type="text" id="score" value="" disabled />
<script>
var score_one = 0;
var score_two = 0;
var score_three = 0;
var score_four = 0;
var totalScore = 0;
function fsubmit(){
var correctFirstAnswer = document.getElementById("price_three");
var correctSecondAnswer = document.getElementById("price_six");
var correctThirdAnswer = document.getElementById("price_seven");
var correctFourthAnswer = document.getElementById("price_eleven");
if (correctFirstAnswer.checked === true){
score_one = 1;
}
if (correctSecondAnswer.checked === true){
score_two = 1;
}
if (correctThirdAnswer.checked === true){
score_three = 1;
}
if (correctFourthAnswer.checked === true){
score_four = 1;
}
totalScore = score_one + score_two + score_three +score_four;
}
document.getElementById("score").value = totalScore;
</script>
My PHP code snippet is:
$email = $_POST['email'];
$name = $_POST['name'];
$score = $_POST['score'];
$body = <<<EOD
Name: $name <br>
Email: $email <br>
Score: $score <br>
A typical reply is: Name: Mr Bloggs Email: bloggs@bloggs.com Score:
I get no value at all in the Score: part - no zero or anything.
Can anyone help? I would be really grateful - I'm not an expert coder, just muddling through really.
`. And do think about escaping your input values. – Funk Forty Niner Nov 30 '13 at 21:25