klpang Posted March 30, 2006 Share Posted March 30, 2006 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"> <INPUT TYPE="checkbox" VALUE="Streamyx" NAME="txtc">Streamyx</FONT></TD> <TD WIDTH="50%"><FONT COLOR="#000000"> <INPUT TYPE="checkbox" VALUE="Maxis" NAME="txtc">Maxis</FONT></TD></TR><TR> <TD WIDTH="50%"><FONT COLOR="#000000"> <INPUT TYPE="checkbox" VALUE="Jaring" NAME="txtc">Jaring</FONT></TD> <TD WIDTH="50%"> <FONT COLOR="#000000"> <INPUT TYPE="checkbox" VALUE="Time" NAME="txtc">Time</FONT></TD></TR><TR> <TD WIDTH="50%"><FONT COLOR="#000000"> <INPUT TYPE="checkbox" VALUE="Dailup" NAME="txtc">Dial up</FONT></TD> <TD WIDTH="50%"> <FONT COLOR="#000000"> <INPUT TYPE="checkbox" VALUE="myLynx" NAME="txtc">myLynx</FONT></TD></TR><TR> <TD WIDTH="50%"><FONT COLOR="#000000"> <INPUT TYPE="checkbox" VALUE="others" NAME="txtc[]">Others <INPUT NAME="txtcothers"></FONT></TD> <TD WIDTH="50%"></TD></TR>thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/6143-solved-how-to-capture-mutiple-check-box-value-in-php/ Share on other sites More sharing options...
craygo Posted March 30, 2006 Share Posted March 30, 2006 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 Link to comment https://forums.phpfreaks.com/topic/6143-solved-how-to-capture-mutiple-check-box-value-in-php/#findComment-22169 Share on other sites More sharing options...
klpang Posted March 30, 2006 Author Share Posted March 30, 2006 [!--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? Quote Link to comment https://forums.phpfreaks.com/topic/6143-solved-how-to-capture-mutiple-check-box-value-in-php/#findComment-22183 Share on other sites More sharing options...
craygo Posted March 30, 2006 Share Posted March 30, 2006 Check Boxes have to have different names. if you like name them txtc1, txtc2,txtc3, ect....Ray Quote Link to comment https://forums.phpfreaks.com/topic/6143-solved-how-to-capture-mutiple-check-box-value-in-php/#findComment-22186 Share on other sites More sharing options...
Guest footballkid4 Posted March 30, 2006 Share Posted March 30, 2006 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]<?phpif ( isset( $_POST['txtc'] ) ){ print_r( $_POST['txtc'] );}?>[/code]You will see all of the posted checkboxes Quote Link to comment https://forums.phpfreaks.com/topic/6143-solved-how-to-capture-mutiple-check-box-value-in-php/#findComment-22207 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.