checkbox help needed

J

jeep

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">quite a bit <INPUT TYPE=RADIO NAME="PCLM1" VALUE="agree strongly">extremely<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="return 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
 
K

kaeli

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.

Tested successfully in IE.

<script type="text/javascript" language="javascript">
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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,169
Latest member
ArturoOlne
Top