checkbox help needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jeep@55.usenet.us.com

    checkbox help needed

    Im totally new to javascript. Im working on a webpage that I need to
    make sure the user has checked at least one answer to each question
    in the list. I cant seem to figure out the logic or something.

    All the input lines in html look like this:

    1.&nbsp;<INPUT TYPE=RADIO NAME="PCLM1" VALUE="disagree strongly">
    not at all<INPUT TYPE=RADIO NAME="PCLM1" VALUE="disagree ">
    a little bit&nbsp; <INPUT TYPE=RADIO NAME="PCLM1" VALUE="neutral" >
    moderately <INPUT TYPE=RADIO NAME="PCLM1" VALUE="agree">q uite a bit <INPUT TYPE=RADIO NAME="PCLM1" VALUE="agree strongly">extre mely<BR>

    All are named PCLMx

    there are 17 of these. I need a script that will tell me when one or more
    of the answers were not checked at all so the user can complete the form
    and I can move on.

    I have the post line working ok to call my script, just not the logic:

    <form method="POST" action="http://www.site.com/cgi-bin/mil_pclm.pl" onSubmit="retur n check_form(this );">


    Ive looked all over the web and cant seem to find an answer to this particular
    problem.

    I need your help :)
    Thank you so much!
    Jeff

    --
    If you falter in times of trouble, how small is your strength!
    - Proverbs 24:10 (NIV)

  • kaeli

    #2
    Re: checkbox help needed

    In article <bkt2hd$ind$1@b lue.rahul.net>, jeep@55.usenet. us.com
    enlightened us with...[color=blue]
    > Im totally new to javascript. Im working on a webpage that I need to
    > make sure the user has checked at least one answer to each question
    > in the list. I cant seem to figure out the logic or something.
    >[/color]

    Tested successfully in IE.

    <script type="text/javascript" language="javas cript">
    function check_form(f)
    {
    var forgot;
    for (var i=1; i<18; i++)
    {
    forgot=true;
    var l=f.elements["PCLM"+i].length;
    for (j=0; j<l; j++)
    {
    if (f.elements["PCLM"+i][j].checked==true) forgot=false;
    }
    if (forgot)
    {
    alert("You forgot one. Number: "+i);
    return false;
    }
    }
    return true;
    }
    </script>

    -------------------------------------------------
    ~kaeli~
    All I ask for is the chance to prove that money
    cannot make me happy.


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

    Comment

    Working...