PDA

View Full Version : checkbox looping question


charbort
01-27-2003, 03:03 PM
Still learning, but I think this code cycles through to see which checkboxes are selected and sets the value to the input value, but how do I make it only alert if they don't check any checkboxes?

Thanks,
charbort


function CheckValues(){
var Rtn = false

if(document.signUp.subject1.checked == true){
alert(document.signUp.subject1.value);}
if(document.signUp.subject2.checked == true){
alert(document.signUp.subject2.value);}
if(document.signUp.subject3.checked == true){
alert(document.signUp.subject3.value);}
if(document.signUp.subject4.checked == true){
alert(document.signUp.subject4.value);}
if(document.signUp.subject5.checked == true){
alert(document.signUp.subject5.value);}

return Rtn;



------ HTML CODE -----

<form name="signUp" method="POST" action="FormMail.cgi" onSubmit='SubmitForm(this);'>

<input name='subject1' type='checkbox' value='Subscribe 1'>
<input name='subject2' type='checkbox' value='Subscribe 2'>
<input name='subject3' type='checkbox' value='Subscribe 3'>
<input name='subject4' type='checkbox' value='Subscribe 4'>
<input name='subject5' type='checkbox' value='Subscribe 5'>

A1ien51
01-27-2003, 05:03 PM
function CheckIt(){
nc=0;
numCheck=5;
for(i=1;i<=numCheck;i++){
if(document.signUp["subject"+i].checked==false)nc++;
}
if(nc==0)alert('None were checked');
}

charbort
01-27-2003, 05:39 PM
shouldn't it read

"if(document.signUp["subject"+i].checked==true)nc++; "

true instead of false? I changed it and it seems to be working great.

Thanks a lot,
Charbort