By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,937 Members | 1,532 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,937 IT Pros & Developers. It's quick & easy.

checkbox help needed

P: n/a
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

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

Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <bk**********@blue.rahul.net>, je**@55.usenet.us.com
enlightened us with...
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
-------------------------------------------------
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.