Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/local/bin/perl -wT use strict; my $template_file="../go/class/quiz/quiz.tmpl"; my $quiz_data_file="./quizes/70-215-1.txt"; #********** # quiz.pl # dan@ltc.org #********** use CGI; my $q=new CGI; print $q->header(); open(FH,$quiz_data_file) or die"$! couldn't open quiz.txt\n"; my @lines=<FH>; close(FH) or die"$! couldn't close quiz.txt"; my @quiz=(); my @answers=(); my $question_count=0; my $numElements=0; for ($question_count=0;$question_count<@lines;$question_count++){ my @fields=split('\t',$lines[$question_count]); my $a={}; #answer $numElements+=(@fields-2); $a->{'answer'}=shift(@fields); $a->{'answer_id'}='"q'.$question_count.'"'; push @answers,$a; my $q={}; #question $q->{'question'}=shift(@fields); $q->{'image_name'}="q$question_count".'_image'; my $choice_count=0; my $c=[]; my $letter='a'; while(@fields){ my $choice_items={}; $choice_items->{'choice_name'}="q$question_count"; $choice_items->{'choice_value'}=$letter++; $choice_items->{'choice_text'}=shift(@fields); push (@$c,$choice_items); } $q->{choices}=$c; push @quiz,$q; } use HTML::Template; my $t=HTML::Template->new(filename=>$template_file); $t->param(QUIZ=>\@quiz); $t->param(ANSWERS=>\@answers); $t->param(numElements=>$numElements, numQues=>$question_count); print $t->output(); #################################################### #################################################### <html> <head> <!-- quiz.tmpl huge parts of this html form lifted straight from Charity Kahn's builder.com quizbuilder script. --> <title>Quiz</title> <script language="JavaScript" SRC=/go/class/quiz/quiz.js></script> <script language="JavaScript"> <!-- var numElements = <TMPL_VAR NAME="numElements">; var numQues = <TMPL_VAR NAME="numQues">; var answers = new Array(1); <TMPL_LOOP NAME="ANSWERS"> answers[<TMPL_VAR NAME="answer_id">] ="<TMPL_VAR NAME="answer">"; </TMPL_LOOP> // --> </script> </head> <body > <form name="quiz"> <ol compact type=1> <TMPL_LOOP NAME="QUIZ"> <li><TMPL_VAR NAME="question"> <img src="/go/class/quiz/blank.gif" width=78 height=26 name="<TMPL_VAR NAME="image_name">" align="top"> </li> <ol type='a' compact> <TMPL_LOOP NAME="choices"> <li><input type="radio" name="<TMPL_VAR NAME="choice_name">" value="<T +MPL_VAR NAME="choice_value">"> <TMPL_VAR NAME="choice_text"> </li> </TMPL_LOOP> </ol> <br> </TMPL_LOOP> </ol> <input type="button" value="Get score" onClick="getScore(this.form +)"> <input type="reset" value="Clear"><p> Score = <input type=text size=15 name="percentage"><br> </form> </body></html> ################################################ ################################################ // dan@ltc.org // quiz.js // // Except for the bits that change the image // and the bits that allow variable number of // choices, this script is lifted straight from // from Charity Kahn's builder.com // quizbuilder script. var wrongImage = new Image(78,26); wrongImage.src = "/go/class/quiz/wrong.gif" var blankImage = new Image(78,26); blankImage.src = "/go/class/quiz/blank.gif" function getScore(form) { var score = 0; var c; var imageName; var prev=0; var cur=0; var isBlank; while(cur<numElements){ isBlank=true; while(form.elements[cur].name==form.elements[prev].name){ c=form.elements[cur]; if(c.checked){ isBlank=false; if(c.value==answers[c.name]){ score++; imageName=c.name+"_image"; document.images[imageName].src=blankImage.src; }else{ imageName=c.name+"_image"; document.images[imageName].src=wrongImage.src; } } cur++; } if (isBlank){ c=form.elements[prev]; imageName=c.name+"_image"; document.images[imageName].src=wrongImage.src; } prev=cur; } score = Math.round(score/numQues*100); form.percentage.value = score + "%"; }

In reply to yet another quiz script by mandog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (5)
    As of 2014-09-23 03:01 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (210 votes), past polls