/    Sign up×
Community /Pin to ProfileBookmark

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 )

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@screamingbuddhaauthorNov 21.2002 — 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.
Copy linkTweet thisAlerts:
@screamingbuddhaauthorNov 21.2002 — 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.Q?;

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();"
×

Success!

Help @screamingbuddha spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...