ldbkutty
asked on
Checkbox Array problem..
This example works :
<HTML>
<HEAD>
<SCRIPT LANGUAGE=javascript>
function atLeastOne(){
var objForm = document.forms[0];
for(i=0;i<4;i++){
if(objForm.elements["frm_c hk_delete[ " + i + "]"].checked){
return true;
}
}
alert("Please check at least one box!");
return false;
}
</SCRIPT>
</HEAD>
<BODY>
<form name="frmYourForm" action="yourpage.htm" onSubmit="return atLeastOne()">
<INPUT type="checkbox" name="frm_chk_delete[0]">< br>
<INPUT type="checkbox" name="frm_chk_delete[1]">< br>
<INPUT type="checkbox" name="frm_chk_delete[2]">< br>
<INPUT type="checkbox" name="frm_chk_delete[3]">< br>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</FORM>
</BODY>
</HTML>
but I have the checkboxes like this (within php) :
<INPUT type="checkbox" name="frm_chk_delete[]"><b r>
<INPUT type="checkbox" name="frm_chk_delete[]"><b r>
<INPUT type="checkbox" name="frm_chk_delete[]"><b r>
<INPUT type="checkbox" name="frm_chk_delete[]"><b r>
How should the validation be done?
PS: I dont want to change the element name and if possible, dont want to add "id" also. The above is just an example for my problem. Original form has various checkboxes with numerous fields.
<HTML>
<HEAD>
<SCRIPT LANGUAGE=javascript>
function atLeastOne(){
var objForm = document.forms[0];
for(i=0;i<4;i++){
if(objForm.elements["frm_c
return true;
}
}
alert("Please check at least one box!");
return false;
}
</SCRIPT>
</HEAD>
<BODY>
<form name="frmYourForm" action="yourpage.htm" onSubmit="return atLeastOne()">
<INPUT type="checkbox" name="frm_chk_delete[0]"><
<INPUT type="checkbox" name="frm_chk_delete[1]"><
<INPUT type="checkbox" name="frm_chk_delete[2]"><
<INPUT type="checkbox" name="frm_chk_delete[3]"><
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</FORM>
</BODY>
</HTML>
but I have the checkboxes like this (within php) :
<INPUT type="checkbox" name="frm_chk_delete[]"><b
<INPUT type="checkbox" name="frm_chk_delete[]"><b
<INPUT type="checkbox" name="frm_chk_delete[]"><b
<INPUT type="checkbox" name="frm_chk_delete[]"><b
How should the validation be done?
PS: I dont want to change the element name and if possible, dont want to add "id" also. The above is just an example for my problem. Original form has various checkboxes with numerous fields.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks and welcome back (to form) :=)
I opted first one as it seems faster.
I opted first one as it seems faster.
thanks kutty!
pride in answering ur questiion..
pride in answering ur questiion..
function atLeastOne(){
var objForm = document.forms[0].elements
for(i=0;i<objForm.length;i
if(objForm[i].type == "checkbox" && objForm[i].name.indexOf('f
return true;
}
}
alert("Please check at least one box!");
return false;
}