Zhadus Posted January 25, 2008 Share Posted January 25, 2008 Ok, thank you for trying to help me in advance. First off, what I am trying to do is this. I have an autopopulated list of names with checkboxes. I also used some javascript so that I could "check all" or "uncheck all." And then I created some more javascript to output values as to whether the submit should be active or disabled. As you select names it calculates 2 person teams, and how many matches would be need for every team to play at least once. What I need is to send an array of the "checked" names to another page when I submit the form. Here is my javascript: function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } function tcheck(field) { var x=0; for (i = 0; i < field.length; i++) { if (field[i].checked == true) x++; } if (x%2==0) { document.mainform.tdisp.value = (x/2); if ((x/2)>1){ mcheck(x); } else { document.mainform.mdisp.value = "X"; document.mainform.pbutton.disabled = true; } } else { document.mainform.tdisp.value = "X"; document.mainform.mdisp.value = "X"; document.mainform.pbutton.disabled = true; } } function mcheck(val) { if ((val%2)!=0) { val = (val+(val%2))/2; } else { val = val/2; } if ((val%2)!=0) { val = (val+(val%2))/2; } else { val = val/2; } num = val; document.mainform.mdisp.value = num; document.mainform.pbutton.disabled = false; } and here it the page: <html> <head> </head><body> <script language=javascript src=clancomp.js> </script> <?php $members = array("Name1", "Name2", "Name3", "Name4", "Name5", "Name6", "Name7", "Name8", "Name9", "Name10", "Name11", "Name12", "Name13", "Name14"); $memnum = sizeof($members); echo "<form name=mainform action=compcalc.php method=post><table border=0 width=500><tr><td>Select Members:</td><td> </td><td><input type=button name=CheckAll value=\"Check All\" onclick=checkAll(document.mainform.memlist)></td><td><input type=button name=UnCheckAll value=\"Uncheck All\" onclick=uncheckAll(document.mainform.memlist)></td></tr>"; $count=0; while ($count<$memnum) { $count2=0; echo "<tr>"; while (($count2<4) and ($members[$count+$count2]!=null)) { echo "<td><input type=checkbox name=memlist onclick=tcheck(document.mainform.memlist) value=" . $members[$count+$count2] . ">" . $members[$count+$count2] . "</td>"; $count2++; } echo "</tr>"; $count = $count+4; } echo "<tr><td colspan=4> </td></tr><tr><td>Teams: <input type=text name=tdisp size=2 readonly=true></td><td>Matches: <input type=text name=mdisp size=2 readonly=true></td><td></td><td><input type=submit name=pbutton value=\"Post Teams\" disabled=true action=submit></td></tr></table></form>"; ?> </body> </html> Thank you guys for any help. Quote Link to comment https://forums.phpfreaks.com/topic/87811-solved-php-array-form-post-and-javascript/ Share on other sites More sharing options...
resago Posted January 25, 2008 Share Posted January 25, 2008 as you have it now. use javascript: var boxes; on submit, run through ALL the checkboxes. if checked { boxes+='+on'; else boxes+='+off'; } then put the boxes var in a hidden form element like <script> document.formname.boxesf.value=boxes; <input name=boxesf type=hidden> then in php, explode the string, seperate on + Quote Link to comment https://forums.phpfreaks.com/topic/87811-solved-php-array-form-post-and-javascript/#findComment-449295 Share on other sites More sharing options...
Zhadus Posted January 26, 2008 Author Share Posted January 26, 2008 Perfect, thank you so much. Quote Link to comment https://forums.phpfreaks.com/topic/87811-solved-php-array-form-post-and-javascript/#findComment-449770 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.