Hi Guys,
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.
[CODE=javascript]
function checkBox()
{
alert("Q1");
// Validate Check boxs
//-------------------------
var filledIn = false;
alert(document. forms[0].chkSectionInte rested.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<documen t.forms[0].chkSectionInte rested.length; counter++)
{
if (document.forms[0].chkSectionInte rested[counter].checked == true)
{
filledIn = true;
//else{
if (document.forms[0].chkSectionInte rested.checked == true)
{
filledIn = true;
}
}
}
if (filledIn == false)
{
alert('Please select your area of interest');
document.forms[0].chkSectionInte rested[0].focus();
return(false);
}
return (true);
}
[/CODE]
[HTML]
<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.
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.
[CODE=javascript]
function checkBox()
{
alert("Q1");
// Validate Check boxs
//-------------------------
var filledIn = false;
alert(document. forms[0].chkSectionInte rested.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<documen t.forms[0].chkSectionInte rested.length; counter++)
{
if (document.forms[0].chkSectionInte rested[counter].checked == true)
{
filledIn = true;
//else{
if (document.forms[0].chkSectionInte rested.checked == true)
{
filledIn = true;
}
}
}
if (filledIn == false)
{
alert('Please select your area of interest');
document.forms[0].chkSectionInte rested[0].focus();
return(false);
}
return (true);
}
[/CODE]
[HTML]
<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.
Comment