[thelist] request JS help for quiz

Sharon F. Malone sfmalo at 24caratdesign.com
Mon Jul 22 20:47:01 CDT 2002


Hi Kristol -

When I tried re-writing it (because each question is wrapped in <.form><./form> tags!!!!!!), it totally bombed. Since my JS knowledge is not so hot, I worked around the original code and got it to work.

Thanks for the quiz code you provided. I'll work with it the next time.

Best,
Sharon

From: "Kristof Neirynck" <k.neirynck at belgacom.net>
Sent: Monday, July 22, 2002 7:06 AM

> I don't quite see why you'd write it that way
> this is how I do it
>
> Kristof
>
> <script type="text/javascript">
>     //f = name of form
>     //n = name of group
>     function getValue(f,n)
>     {
>         var g = document.forms[f].elements[n];
>         var retval = 'error - none checked';//value of the checker
> radoibutton
>         var retnr = -1;//number of the checked radiobutton
>         for (var i = 0; i<g.length; i++)
>         {
>             if (g[i].checked)
>             {
>                 retval = g[i].value;
>                 retnr = i;
>             }
>         }
>         //return retval;//choose what you want returned (in your case
> the number)
>         return retnr;
>     }
> </script>
>
>
> <form name="quizform"
> onsubmit="alert(getValue('quizform','question_01'));return false;">
> What's the number?<br />
> <input type='radio' name='question_01' value='one' />1<br />
> <input type='radio' name='question_01' value='two' />2<br />
> <input type='radio' name='question_01' value='three' />3<br />
> <input type='radio' name='question_01' value='four' />4<br />
> <input type='submit' value=' - Submit - '>
> </form>
---------------------------------------------------------------------------
Sharon F. Malone
"web design and Internet writing services"
http://www.24caratdesign.com
sfmalo at 24caratdesign.com




More information about the thelist mailing list