HELP! Simple Javascript Problem, Simpler Me!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • not@this.time

    HELP! Simple Javascript Problem, Simpler Me!

    Hello All,

    I am trying to develop a relatively simple self-quiz form in
    javascript, but I'm having no luck getting it to work.

    What I am looking for is a script that allow the user to select one of
    three answers for each question, and automatically assign a value to
    their answer ("never"=0, "sometimes" =1, "always"=2) . There would be
    anywhere from ten to thirty questions. I want the script to calculate
    the running total, and then display that total at the bottom of the
    input section. FYI, there I would add text to the effect of "your
    total score is [x]. A score of 0-10 means this, 11-20 means that, and
    21-30 means somthing else."

    Conceptually it seems so simple to me. But all the scripts I write
    (or, actually, find-and-tweak) either over-calculate (in other words,
    multiple clicks on a "yes" radio button increase the total) or only
    calculate the last set of values (i.e. question 5 out of 5 but not
    1-4). Any help would be most appreciated.

    Munged code follows. I've stripped it down to its essentials (actually
    well beyond that, hence the problem). There's a big hole where the
    javascript itself should go. I feel certain there's a straightforward
    solution to this. Yet it's seemingly beyond me....

    Bill

    -----------------------------

    <head>
    <SCRIPT LANGUAGE="JavaS cript">
    <!-- Begin
    // End -->
    </script>
    </head>

    <body>

    <form method="POST" name="myform">

    <table border=1 cellpadding=2>

    <tr>
    <td align=center>Ne ver</td>
    <td align=center>So metimes</td>
    <td align=center>Al ways</td>
    <td>&nbsp;</td>
    </tr>

    <tr>
    <td align=center valign=top><inp ut type="radio" name="1"
    onclick="this.f orm.total.value =0;"></td>
    <td align=center valign=top><inp ut type="radio" name="1"
    onclick="this.f orm.total.value =1;"></td>
    <td align=center valign=top><inp ut type="radio" name="1"
    onclick="this.f orm.total.value =2;"></td>
    <td valign=top>I eat breakfast.
    </tr>

    <tr>
    <td align=center valign=top><inp ut type="radio" name="2"
    onclick="this.f orm.total.value =0;"></td>
    <td align=center valign=top><inp ut type="radio" name="2"
    onclick="this.f orm.total.value =1;"></td>
    <td align=center valign=top><inp ut type="radio" name="2"
    onclick="this.f orm.total.value =2;"></td>
    <td valign=top>I eat lunch.</td>
    </tr>

    <tr>
    <td colspan=4>Your score is: <input type="text" name="total"
    readonly onFocus="this.b lur();"></td>
    </tr>

    </table>

    </form>

    </body>
  • Mick White

    #2
    Re: HELP! Simple Javascript Problem, Simpler Me!

    not@this.time wrote:[color=blue]
    > Hello All,
    >
    > I am trying to develop a relatively simple self-quiz form in
    > javascript, but I'm having no luck getting it to work.
    >
    > What I am looking for is a script that allow the user to select one of
    > three answers for each question, and automatically assign a value to
    > their answer ("never"=0, "sometimes" =1, "always"=2) . There would be
    > anywhere from ten to thirty questions. ...[/color]


    Mick

    Comment

    • not@this.time

      #3
      Re: HELP! Simple Javascript Problem, Simpler Me!

      On Thu, 06 Jan 2005 21:50:53 GMT, Mick White
      <mwhite13BOGUS@ rochester.rr.co m> wrote:
      [color=blue]
      >http://www.mickweb.com/javascript/fo...tedSurvey.html[/color]

      Amazing. Thank you VERY much.

      Comment

      Working...