/    Sign up×
Community /Pin to ProfileBookmark

I am struggling to get to grips with this….

I have x number of radiobutton groups – say 3 in each group

question 1 is it ans a, b, or c? answer e.g. a is correct
question 2 ………………….answer e.g. c is correct etc….

I want to display some feedback to each question once all questions have been answered.

Can anyone help? Some extra JS comments would also be useful…

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Jun 29.2004 — <i>
</i>&lt;script type="text/javascript"&gt;
function showAnswer(){
var f=document.forms[0];
var wrong=true;

<i> </i> for(i=0;i&lt;f.q1.length;i++){

<i> </i> if(f["q1_a"].value==f.q1[i].value){
<i> </i> wrong=false;
<i> </i> break;
<i> </i> }else{
<i> </i> wrong=true;
<i> </i> }
<i> </i>}

<i> </i>if(wrong==false){
<i> </i> alert("You got the answer right!")
<i> </i>}else{
<i> </i> alert("Wrong Answer!");
<i> </i>}
}
&lt;/script&gt;

&lt;form&gt;
&lt;input type="radio" name="q1" value="a"&gt; Answer A&lt;br/&gt;
&lt;input type="radio" name="q1" value="b"&gt; Answer B&lt;br/&gt;
&lt;input type="radio" name="q1" value="c"&gt; Answer C&lt;br/&gt;
&lt;input type="hidden" name="q1_a" value="a"/&gt;
&lt;input type="button" onclick="showAnswer()" value="Check"/&gt;
&lt;/form&gt;

Copy linkTweet thisAlerts:
@BhanuJun 29.2004 — you can modify this as per your requirement

Bhanu

==========================================

<html>

<head>

<title>Bhanu</title>

<script language="JavaScript">

function check(){

for(a=1;a<5;a++){

for(i=0;i<3;i++){

x = "q" + a;

if(document.all[x][i].checked == true){alert(document.all['q1'][i].value);}

}

}

}

</script>

</head>



<body>

<form action="" name="test" onsubmit="return check();">

Q1: xxxxxxxxxxx?<br>

<input type="Radio" name="q1" value="a">A<br>

<input type="Radio" name="q1" value="b">B<br>

<input type="Radio" name="q1" value="c">C<br>

Q2: xxxxxxxxxxx?<br>

<input type="Radio" name="q2" value="a">A<br>

<input type="Radio" name="q2" value="b">B<br>

<input type="Radio" name="q2" value="c">C<br>

Q3: xxxxxxxxxxx?<br>

<input type="Radio" name="q3" value="a">A<br>

<input type="Radio" name="q3" value="b">B<br>

<input type="Radio" name="q3" value="c">C<br>

Q4: xxxxxxxxxxx?<br>

<input type="Radio" name="q4" value="a">A<br>

<input type="Radio" name="q4" value="b">B<br>

<input type="Radio" name="q4" value="c">C<br>

<input type="Submit" value="Submit">

</form>

</body>

</html>
==========================================

×

Success!

Help @jcc 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 6.15,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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