/    Sign up×
Community /Pin to ProfileBookmark

customize quiz

Link to page: [url]http://test.kyvu.org/learning/virtual101.htm[/url]
I’ve been given this quiz (yes, the HTML coding is bad — I’m working on fixing that right now), and need to tweak it a little, so that the pertinent message (as seen in the table at the bottom of the page) displays ALONG WITH the score. I admit it, I stink at Javascript, so your help would be appreciated.

Javascript:

[code] <script type=”text/javascript”>
var total = new Array(11);
var score = 0
function displayScore(form,callingField) {
score = 0;
for (i=0; i <=2; i++)
if (form.num1[i].checked) {
total[0] = parseInt(form.num1[i].value);}
for (i=0; i <=2; i++)
if (form.num2[i].checked) {
total[1] = parseInt(form.num2[i].value);}
for (i=0; i <=2; i++)
if (form.num3[i].checked) {
total[2] = parseInt(form.num3[i].value);}
for (i=0; i <=2; i++)
if (form.num4[i].checked) {
total[3] = parseInt(form.num4[i].value);}
for (i=0; i <=2; i++)
if (form.num5[i].checked) {
total[4] = parseInt(form.num5[i].value);}
for (i=0; i <=2; i++)
if (form.num6[i].checked) {
total[5] = parseInt(form.num6[i].value);}
for (i=0; i <=2; i++)
if (form.num7[i].checked) {
total[6] = parseInt(form.num7[i].value);}
for (i=0; i <=2; i++)
if (form.num8[i].checked) {
total[7] = parseInt(form.num8[i].value);}
for (i=0; i <=2; i++)
if (form.num9[i].checked) {
total[8] = parseInt(form.num9[i].value);}
for (i=0; i <=2; i++)
if (form.num10[i].checked) {
total[9] = parseInt(form.num10[i].value);}
for (i=0; i <=2; i++)
if (form.num11[i].checked) {
total[10] = parseInt(form.num11[i].value);}
for (j=0; j <=10; j++)
score = score + total[j];
form.result.value = score; }

function ClearScore(form){
score = 0
form.result.value = score }

</script>[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@LeeUOct 03.2008 — Not sure what you mean. In FF 2, I select the answers and the score displays w/o changing anything on the page. The table below is still displayed.
Copy linkTweet thisAlerts:
@KDLAauthorOct 04.2008 — Sorry to be vague. Right now, the messages in the table are static HTML. What I'd like to do is have a message appear dynamically with the score total.

So, if the person takes the quiz, clicks submit, the score of say 15 will appear. Along with it, a div with the ID of "medium" (which was initially set to "display: none;") would appear because the style setting would be changed because the score falls within the 11-20 scoring category.

I know it will be dependent upon an "if" statement, but I don't know how to code it to work with the existing javascript.

Something like

if {score <= 20} && {score >= 11}

{document.getElementbyID("low").style.display="block";

if {score <= 28} && {score >=21}

{document.getElementbyID("medium").style.display="block";

if {score <= 33} && {score >= 29}

{document.getElementbyID("high").style.display="block";

Make sense?
×

Success!

Help @KDLA 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.28,
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,
)...