Click to See Complete Forum and Search --> : lil help


screamingbuddha
11-21-2002, 09:26 AM
my first time here, first time posting, and not great at javascript.. etc.. so..
please forgive any breaches of etiquette I may commit while trying to get this problem solved (which has to be solved this morning)..

I'm trying to create a simple 4 question quiz - project standards requiring that any combination of answers redirects to an unique, flat html page, so the function looks like this:

function scoreTest(this.form){
var totalScore = ((form.Q1.value) + (form.Q2.value) + (form.Q3.value) + (form.Q4.value));
if (totalScore == "1357") { openNew('sub/1357.html') }
if (totalScore == "1358") { openNew('sub/1358.html') }

etc.. (with a sub page for all 16 possible variations to Yes/No answers)

it's setting the document that I'm having trouble with..
I can't figure out how to make 4 questions (each with a Yes/No radio) and submit all the radio values by using a final button 'onclick=scoreTest(this.form)'

any help?

thanks in advance ( I think )

screamingbuddha
11-21-2002, 09:53 AM
p.s.
I tried using this as an individual radio value

onclick=Q1.value="1"

but I'm not so sure that it's a very good way of accomplishing this.

screamingbuddha
11-21-2002, 04:04 PM
well it took much longer than I anticipated..

if anyone was interested in the answer, here is the final/cleaned code that works:


function openNew(URL) {
window.open(URL, target="_printChild", 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=300,height=200');
}


function scorequiz()
{

var f1 = getChecked(document.quiz.QA);
var f2 = getChecked(document.quiz.QB);
var f3 = getChecked(document.quiz.QC);
var f4 = getChecked(document.quiz.QD);

var totalScore = ((f1) + (f2) + (f3) + (f4));
alert(totalScore);
openNew("sub/" + totalScore + ".html")

}



function getChecked(group)
{
for ( var i=0; i<group.length; i++ )
{
if ( group[i].checked == true )
{
return group[i].value;
}
}
}

// in body

<input type="radio" value="1" name="QA">
<input type="radio" value="2" name="QA">
<input type="radio" value="3" name="QB">
<input type="radio" value="4" name="QB">
<input type="radio" value="5" name="QC">
<input type="radio" value="6" name="QC">
<input type="radio" value="7" name="QD">
<input type="radio" value="8" name="QD">

button of your chosing - onclick="scorequiz();"