Jump to content

[SOLVED] PHP Array - Form Post - and Javascript


Zhadus

Recommended Posts

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.

Link to comment
Share on other sites

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 +

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.