I am am trying to validate multiple check box. It works fine when checkbox name is like chkSectionInter ested but when i add [] to the name chkSectionInter ested[], then i can validate any more.
I need to keep [] so that i can save data using php collected from this page.
If i remove [] from checkbox name then php only gets last selected value from the check box please help. I have been looking for two days but nothin seems to work.
Expand|Select|Wrap|Line Numbers
- function checkBox()
- {
- alert("Q1");
- // Validate Check boxs
- //-------------------------
- var filledIn = false;
- alert(document.forms[0].chkSectionInterested.length);
- // Use the length property to iterate through each Checkbox
- // to determine if a selection has been made
- // ----- Area Of Interest
- for (var counter=0; counter<document.forms[0].chkSectionInterested.length; counter++)
- {
- if (document.forms[0].chkSectionInterested[counter].checked == true)
- {
- filledIn = true;
- //else{
- if (document.forms[0].chkSectionInterested.checked == true)
- {
- filledIn = true;
- }
- }
- }
- if (filledIn == false)
- {
- alert('Please select your area of interest');
- document.forms[0].chkSectionInterested[0].focus();
- return(false);
- }
- return (true);
- }
<input class="clsSecti onInterested" type="checkbox" name="chkSectio nInterested[]" value="Beauty" style="font-family: Arial; font-size: 10pt; border: 0px solid #C0C0C0; padding: 0">
<input class="clsSecti onInterested" type="checkbox" name="chkSectio nInterested[]" value="Wellness " style="font-family: Arial; font-size: 10pt; border: 0px solid #C0C0C0; padding: 0">
<input class="clsSecti onInterested" type="checkbox" name="chkSectio nInterested[]" value="Saloon" style="font-family: Arial; font-size: 10pt; border: 0px solid #C0C0C0; padding: 0">[/HTML]
PHP Code
[PHP]
$strSectionInte rested="";
$count=count($c hkSectionIntere sted);
for($i=0;$i<$co unt;$i++){$strS ectionIntereste d="$strSectionI nterested$chkSe ctionInterested[$i], ";}[/PHP]
ALL THE CODE WORKS FINE BUT DOES NOT VALIDTAE IF I REMOVE [ ] FROM CHECKBOX NAME AND IF I REMOVE [ ] THEN PHP GET ONLY THE LAST SELECTED VALUE FROM THE CHECK BOX AND ABOVE ALL I HAVE TO VALIDATE SO THAT USER ATLEAST SELECT 1 OPTION.