Forum Moderators: open
I have created a multiple choice test to which answers with different values are assigned. Pressing the "Process!" button the values are added up and depending on the resulting score a new page opens, carrying some information on the result. Obviously, the results are grouped into categories so that I won't have to create a page for every possible score.
What I now am desperately trying to achieve is that the report page also displays the exact number of the score as processed before. I'm thinking of something like a box in the report card to which the result of the test is "transferred". What I've roughly got so far:
}
computeForm(entry.form);
}
function computeForm(form) {
var total = 0
for (var count=0; count<5; count++)
{
if (form.a[count].checked){
var total=total+parseInt(form.a[count].value);
}
}
for (var count=0; count<5; count++)
{
if (form.b[count].checked){
var total=total+parseInt(form.b[count].value);
}
(...and so on and so forth...)
}
if (total<0){ location.href = "Poor.shtml" }
else if (total<25){ location.href = "Okay.shtml" }
else if (total<50){ location.href = "Good.shtml" }
else if (total<100){ location.href = "Excellent.shtml" }
else { location.href = "XYZ.shtml" }
}
Thank you so much for your support!
Are these radio buttons, or checkboxes?
I presume your scroing technique is OK (?)
Re: Passing score
The simpest way is to attach the score via query string
location.href = "Okay.shtml?score="+total;
You can get this in a script in the next page by parsing the string with this function
function getQueryParam(name)
{
location.search.match(new RegExp('[&?]'+name+'=([^&]*)'));
return decodeURIComponent(RegExp.$1);
}
eg
var score = getQueryParam("score");
If you pass the grade too (or decide it on the result page) then you only need one result page document.
I'm using radiobuttons and the scoring seems fine. I've added the code in the test homepage as you suggested as well as the getQueryParam("score") function in the result page. However, I'm afraid I'm too much of a newbie to know how I can get the score to appear in a box in the result page. Could you tell me exactly what lines I need to make the score appear in a textbox - or even better: as a part of the normal text on the report site?
Thank you for your patience!
The only minor problem that I now have is that I just realised the answers in the questionnaire aren't forced field answers. Is there a simple way of adding an alert line that tells the user to answer all the questions before the score is eventually computed?
Edit: Oh, I've just seen you tackled that problem just a few posts earlier. I'll go and try that solution out.