Jump to content


Photo

[SOLVED] how to capture mutiple check box value in php


  • Please log in to reply
4 replies to this topic

#1 klpang

klpang
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 30 March 2006 - 02:55 AM

i have done a HTML form in php script. when i check 2 value in a check box, it just pass 1 value instead of 2 checkbox that i have checked.

i not sure what happen to my script. below is the script that i have done.

please point out the error that i have been made.

for(i=0;i<f.txtc.length;i++)
{
if(f.txtc[i].checked==true)
{
c++;
}
}

if(c==0)
{
alert("Please select 1 or more option in Question 3");
f.txtc[0].focus();
return;
}

if((f.txtc[6].checked==true)&&((Trim(f.txtcothers.value)).length==0))
{
alert("Please fill in the text box in Question 3");
f.txtcothers.focus();
return;
}


Here is the HTML code about the checkbox

<TR>
<TD WIDTH="50%"><FONT COLOR="#000000">&nbsp;&nbsp;&nbsp; <INPUT TYPE="checkbox" VALUE="Streamyx" NAME="txtc">Streamyx</FONT></TD>
<TD WIDTH="50%"><FONT COLOR="#000000">&nbsp;&nbsp;&nbsp; <INPUT TYPE="checkbox" VALUE="Maxis" NAME="txtc">Maxis</FONT></TD>
</TR>
<TR>
<TD WIDTH="50%"><FONT COLOR="#000000">&nbsp;&nbsp;&nbsp; <INPUT TYPE="checkbox" VALUE="Jaring" NAME="txtc">Jaring</FONT></TD>
<TD WIDTH="50%">
<FONT COLOR="#000000">&nbsp;&nbsp;&nbsp; <INPUT TYPE="checkbox" VALUE="Time" NAME="txtc">Time</FONT></TD>
</TR>
<TR>
<TD WIDTH="50%"><FONT COLOR="#000000">&nbsp;&nbsp;&nbsp; <INPUT TYPE="checkbox" VALUE="Dailup" NAME="txtc">Dial up</FONT></TD>
<TD WIDTH="50%">
<FONT COLOR="#000000">&nbsp;&nbsp;&nbsp; <INPUT TYPE="checkbox" VALUE="myLynx" NAME="txtc">myLynx</FONT></TD>
</TR>
<TR>
<TD WIDTH="50%"><FONT COLOR="#000000">&nbsp;&nbsp;&nbsp; <INPUT TYPE="checkbox" VALUE="others" NAME="txtc[]">Others <INPUT NAME="txtcothers"></FONT></TD>
<TD WIDTH="50%"></TD>
</TR>

thanks again.


#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 30 March 2006 - 03:51 AM

the check boxes cannot be the same name, only radio buttons. You have to label them name=txtc[] then a digit will be put in after.

Ray

#3 klpang

klpang
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 30 March 2006 - 04:23 AM

[!--quoteo(post=359888:date=Mar 30 2006, 11:51 AM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 30 2006, 11:51 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
the check boxes cannot be the same name, only radio buttons. You have to label them name=txtc[] then a digit will be put in after.

Ray
[/quote]
but all the checkbox is under a same group. so how?


#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 30 March 2006 - 04:42 AM

Check Boxes have to have different names. if you like name them txtc1, txtc2,txtc3, ect....

Ray

#5 Guest_footballkid4_*

Guest_footballkid4_*
  • Guests

Posted 30 March 2006 - 05:45 AM

This is the best way:
[!--html--][div class=\'htmltop\']HTML[/div][div class=\'htmlmain\'][!--html1--]<input type="checkbox" name="txtc[]" value="Value!" />[!--html2--][/div][!--html3--]
<?php
if ( isset( $_POST['txtc'] ) )
{
     print_r( $_POST['txtc'] );
}
?>
You will see all of the posted checkboxes




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users