/    Sign up×
Community /Pin to ProfileBookmark

Need Help With Quiz

Okay, I really don’t know java at all and all I want to do is make a quiz and have it add up and display the score at the end.

Each radio button has a value and when checked it should add them up at the bottom only I can’t get it to do that. It’s really long sorry!

[code]
<script LANGUAGE=”JavaScript”>
<!–Hide JavaScript from Java-Impaired Browsers function test_it(entry) { if (entry.value!=null && entry.value.length!=0) { entry.value=””+ eval(entry.value);
}
computeForm(entry.form);
}
function computeForm(form) { var total=0 for (var count=0; count<5; count++)
{
if (form.ans1[count].checked){ var total=total+parseInt(form.ans1[count].value);
}
}

for (var count=0; count<5; count++)
{
if (form.ans2[count].checked){ var total=total+parseInt(form.ans2[count].value);
}
}

for (var count=0; count<5; count++)
{
if (form.ans3[count].checked){ var total=total+parseInt(form.ans3[count].value);
}
}

for (var count=0; count<5; count++)
{
if (form.ans4[count].checked){ var total=total+parseInt(form.ans4[count].value);
}
}

for (var count=0; count<5; count++)
{
if (form.ans5[count].checked){ var total=total+parseInt(form.ans5[count].value);
}
}

for (var count=0; count<5; count++)
{
if (form.ans6[count].checked){ var total=total+parseInt(form.ans6[count].value);
}
}

for (var count=0; count<5; count++)
{
if (form.ans7[count].checked){ var total=total+parseInt(form.ans7[count].value);
}
}

for (var count=0; count<5; count++)
{
if (form.ans8[count].checked){ var total=total+parseInt(form.ans8[count].value);
}
}

for (var count=0; count<5; count++)
{
if (form.ans9[count].checked){ var total=total+parseInt(form.ans9[count].value);
}
}

for (var count=0; count<5; count++)
{
if (form.ans10[count].checked){ var total=total+parseInt(form.ans10[count].value);
}
}

if (total<0){ window.location=”http://www.amatterofbalance.com/answer1.html” }
else if (total<25){ window.location=”http://www.amatterofbalance.com/answer2.html” }
else if (total<50){ window.location=”http://www.amatterofbalance.com/answer3.html” }
else if (total<100){ window.location=”http://www.amatterofbalance.com/answer4.html” }
else { window.location=”http://www.amatterofbalance.com/answer5.html” }
}
//–>
</SCRIPT>
</HEAD>
<BODY>
<center><h3>Paper Clutter Quiz</h3></center>
<form METHOD=POST>
<span style=”line-height: 175&#37;;”>
<strong>1. What If someone wanted to come over for a visit, how long would it take you to clean up?</strong><p>
</span><span style=”line-height: 175%;”>
<input name=”ans1″ type=”radio” value=”0″>I wouldn&#8217;t have to do anything.<p>

<input name=”ans1″ type=”radio” value=”2″>One Hour<p>

<input name=”ans1″ type=”radio” value=”5″>One Day<p>

<input name=”ans1″ type=”radio” value=”8″>One Week<p>

<input name=”ans1″ type=”radio” value=”10″>I would ask them not to come.</span><p>

<span style=”line-height: 175%;”>
<strong>2. Would you be able to give a friend a ride in your car if they asked?</strong><p>
</span><span style=”line-height: 175%;”>
<input name=”ans2″ type=”radio” value=”0″>Yes, the whole car is clean.<p>

<input name=”ans2″ type=”radio” value=”2″>Yes, only the trunk is cluttered.<p>

<input name=”ans2″ type=”radio” value=”5″>Yes, if it&#8217;s only one person.<p>

<input name=”ans2″ type=”radio” value=”8″>No, the passenger seat is inaccessible.<p>

<input name=”ans2″ type=”radio” value=”10″>No, the whole car is stuffed and the windows are blocked.<p></span>

<span style=”line-height: 175%;”>
<strong>3. How much of the floor space in your house is covered (with collections of magazines, piles of clothing, stacked boxes, etc) and not available for walking?</strong><p>
</span><span style=”line-height: 175%;”>
<input name=”ans3″ type=”radio” value=”0″>None<p>

<input name=”ans3″ type=”radio” value=”2″>25%<p>

<input name=”ans3″ type=”radio” value=”5″>50%<p>

<input name=”ans3″ type=”radio” value=”8″>75%<p>

<input name=”ans3″ type=”radio” value=”10″>100%</span><p>

<span style=”line-height: 175%;”>
<strong>4. How much of the horizontal surface space (counter tops, tabletops, chair seats, dressers, desktops, coffee table, etc) in your house is covered, and unavailable for intended purpose?</strong><p>
</span><span style=”line-height: 175%;”>
<input name=”ans4″ type=”radio” value=”0″>None<p>

<input name=”ans4″ type=”radio” value=”2″>25%<p>

<input name=”ans4″ type=”radio” value=”5″>50%<p>

<input name=”ans4″ type=”radio” value=”8″>75%<p>

<input name=”ans4″ type=”radio” value=”10″>100%</span><p>

<span style=”line-height: 175%;”>
<strong>5. If you need a particular item or paper document, how long will it take you to find it on average?</strong><p>
</span><span style=”line-height: 175%;”>
<input name=”ans5″ type=”radio” value=”0″>30 Seconds<p>

<input name=”ans5″ type=”radio” value=”2″>15 Minutes<p>

<input name=”ans5″ type=”radio” value=”5″>An Hour<p>

<input name=”ans5″ type=”radio” value=”8″>All Day<p>

<input name=”ans5″ type=”radio” value=”10″>I&#8217;ll Never Find It.</span><p>

<span style=”line-height: 175%;”>
<strong>6. How many of your appliances are functioning perfectly and available for intended use?</strong><p>
</span><span style=”line-height: 175%;”>
<input name=”ans6″ type=”radio” value=”0″>All<p>

<input name=”ans6″ type=”radio” value=”2″>One is not working but is getting fixed.<p>

<input name=”ans6″ type=”radio” value=”5″>Two are not working but they will get repaired within 30 days.<p>

<input name=”ans6″ type=”radio” value=”8″>Several are broken and I have no idea how long they have been.<p>

<input name=”ans6″ type=”radio” value=”10″>None are working and I have no idea when they ever will be again.</span><p>

<span style=”line-height: 175%;”>
<strong>7. In regards to adding more clutter to your life (“Compulsive Acquisition”), how often do you come home with an impulse purchase, and later regret it?</strong><p>
</span><span style=”line-height: 175%;”>
<input name=”ans7″ type=”radio” value=”0″>Never<p>

<input name=”ans7″ type=”radio” value=”2″>Once a month<p>

<input name=”ans7″ type=”radio” value=”5″>Once or Twice a month<p>

<input name=”ans7″ type=”radio” value=”8″>Once a day<p>

<input name=”ans7″ type=”radio” value=”10″>Several times a day and many items.</span><p>

<span style=”line-height: 175%;”>
<strong>8. In regards to adding more clutter to your life (“Compulsive Acquisition”), how often do you come home with freebie fliers or “free” items picked from the curbside trash?</strong><p>
</span><span style=”line-height: 175%;”>
<input name=”ans8″ type=”radio” value=”0″>Never<p>

<input name=”ans8″ type=”radio” value=”2″>Once a month<p>

<input name=”ans8″ type=”radio” value=”5″>Once or Twice a month<p>

<input name=”ans8″ type=”radio” value=”8″>Once a day<p>

<input name=”ans8″ type=”radio” value=”10″>Several times a day and many items.</span><p>

<span style=”line-height: 175%;”>
<strong>9. How difficult is it for you to let go of things?</strong><p>
</span><span style=”line-height: 175%;”>
<input name=”ans9″ type=”radio” value=”0″>I have no problem getting rid of things, I am a &#8220;tosser&#8221;.<p>

<input name=”ans9″ type=”radio” value=”2″>I am hesitant but I can let it go.<p>

<input name=”ans9″ type=”radio” value=”5″>I hang on to things but will let it go if to a good home.<p>

<input name=”ans9″ type=”radio” value=”8″>I struggle with &#8220;I may need it later&#8221; and hang onto most things.<p>

<input name=”ans9″ type=”radio” value=”10″>I am paralyzed about the thought of letting anything go so nothing gets removed from my space.</span><p>

<span style=”line-height: 175%;”>
<strong>10. How much does the clutter in my life impact personal relationships?</strong><p>
</span><span style=”line-height: 175%;”>
<input name=”ans10″ type=”radio” value=”0″>It has no effect on personal relationships.<p>

<input name=”ans10″ type=”radio” value=”2″>It only has a small minor effect on my relationships.<p>

<input name=”ans10″ type=”radio” value=”5″>It has an effect on my relationships, but we are working through compromises on it.<p>

<input name=”ans10″ type=”radio” value=”8″>It is causing increasing stress on relationships, nothing seems to help, I am worried about the future.<p>

<input name=”ans10″ type=”radio” value=”10″>I have already lost a relationship because of clutter.<p></span>
<span style=”line-height: 175%;”>

<input type=button onclick=”doIt(this.form)” value=”Find totals”>
<BR>Your Score: <input size=5 type=text name=clicked value=0 onfocus=blur()>

</form>

</BODY>
</HTML>[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@omnicityOct 01.2010 — Your button trys to call a function called: doIt

but the closest match in your JavaScript (it isn't Java by the way) is: test_it

Not sure if the comment field mangled your code, but be careful at the top - you have an HTML comment within the script tag, so change:

[CODE]<script LANGUAGE="JavaScript">
<!--Hide JavaScript from Java-Impaired Browsers function test_it(entry) { if (entry.value!=null && entry.value.length!=0) { entry.value=""+ eval(entry.value);
}
[/CODE]


into:

[CODE]<script LANGUAGE="JavaScript">
function test_it(entry)
{
if (entry.value!=null && entry.value.length!=0)
{
entry.value=""+ eval(entry.value);
}
[/CODE]


Properly formatting your code will also help you to spot mistakes with nesting, which can be infuriating to debug.
×

Success!

Help @rozalski 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.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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