Jump to content

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


klpang

Recommended Posts

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.
[!--quoteo(post=359888:date=Mar 30 2006, 11:51 AM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 30 2006, 11:51 AM) [snapback]359888[/snapback][/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?
Guest footballkid4
This is the best way:
[!--html--][div class=\'htmltop\']HTML[/div][div class=\'htmlmain\'][!--html1--]<[color=blue]input type[/color]="[color=orange]checkbox[/color]" name="[color=orange]txtc[][/color]" value="[color=orange]Value![/color]" />[!--html2--][/div][!--html3--]
[code]<?php
if ( isset( $_POST['txtc'] ) )
{
     print_r( $_POST['txtc'] );
}
?>[/code]
You will see all of the posted checkboxes

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.