I have a form that has several radio groups that is used as a multiple choice test for users. Currently the form data is submitted to the educator via email. The poster receives and auto-reply email confirming the test was received. I would like to include the results of the test in the email.
How do I capture the value of each radio group and then add them altogether to get the final score. And then, how do I pass that value to a text box (or something) so that I can include it on the auto-reply email. I have found several articles/tutorial on this type of thing but I don't understand it enough to make it work.
If someone could help, I would be just too greatful.

You have to use a for loop to scan each group of radio buttons to find out which one has the attribute "checked" being true. Use the index of the loop as the value of the radio button found checked.

Then compare the values checked with the correct values. If the value is correct, add its worth to the score.

put the whole address of the text box on the left side of an assignment to put the score in the text box.

Thank you for your response. I have this code which produces the results that I am looking for but it has no error handling so if any questions are not completed, the score does not calculate. I have tried doing a loop function but I can't get it working for some reason.

<Script language = JavaScript>


function checkQonea(Q1a){


document.forms[0].Q1aScore.value=Q1a
}



function checkQoneb(Q1b){


document.forms[0].Q1bScore.value=Q1b
}


function calculate(){
A=eval(document.forms[0].Q1aScore.value)
B=eval(document.forms[0].Q1bScore.value)
C=(A+B)
document.forms[0].total.value = C+"%"


}
function message(){
result = C


if (result < 4) {


alert("I'm sorry.  You did not score the minimum 80%.  Please try again.")


}
else if(result >= 4) {


alert("Congratulations! You passed.  Please submit your test now.")


}



}
</SCRIPT>

Just put a -1 in for the selection variable before starting the loop (which will set it to a value from 0 to one less than the number of buttons if a button is clicked). Treat a no-answer like a wrong answer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.