wigglebrother
Technical User
Below is code that provides the checks I need, inserts variables into a checkbox array and checks to see if at least one checkbox is selected. The problem is that the values attached to the checkbox are not carried forward to the print section. If part 2 is selected, the output is
Here We Are.
P choice 0
a choice 1
r choice 2
t choice 3
choice 4
2 choice 5
whereas I need it to output blanks for everything but choice 2.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<script Language="javascript">
function CheckRB_onsubmit() {
var field = document.forms["partsform"].elements["Choice"];
for (i=0; i< field.length; i++){
if (field.checked==true)
return true;
}
alert("You must select either Part1, Part2 or Part3");
return false;
}
</script>
</head>
<body>
<?php
$loop_counter = 0;
$part_counter = 4;
?>
<table>
<form name="partsform" method="post" action="test2.php?authorize=entered" onSubmit="return CheckRB_onsubmit()">
<?php
while($loop_counter < $part_counter)
{
?>
<tr>
<td>
Part<?php echo $loop_counter;?> <input name="Choice" type="checkbox" value="Part <?php echo $loop_counter;?>">
</td>
</tr>
<?php
++$loop_counter;
}
?>
</table>
<input name="parts" type="submit" id="parts" value="Select Part">
</form>
<?php
echo $authorize;
if($authorize == entered)
{
echo"Here We Are.<BR>";
echo $Choice[0]." choice 0<br>";
echo $Choice[1]." choice 1<br>";
echo $Choice[2]." choice 2<br>";
echo $Choice[3]." choice 3<br>";
echo $Choice[4]." choice 4<br>";
echo $Choice[5]." choice 5<br>";
}
?>
</body>
</html>
If the code is modified as shown below, (Choice value with loop counter) the check for checkboxes fails but the output is what I am looking for in that is echoes and carries forward the parts selected:
Part<?php echo $loop_counter;?> <input name="Choice[<?php echo $loop_counter;?>]" type="checkbox" value="Part <?php echo $loop_counter;?>">
Here We Are.
choice 0
choice 1
Part 2 choice 2
choice 3
choice 4
choice 5
How do I form a checkbox array, check for at least one box being checked, yet carry the values forward for utilization later in the scripts?
TIA
Joe
Here We Are.
P choice 0
a choice 1
r choice 2
t choice 3
choice 4
2 choice 5
whereas I need it to output blanks for everything but choice 2.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<script Language="javascript">
function CheckRB_onsubmit() {
var field = document.forms["partsform"].elements["Choice"];
for (i=0; i< field.length; i++){
if (field.checked==true)
return true;
}
alert("You must select either Part1, Part2 or Part3");
return false;
}
</script>
</head>
<body>
<?php
$loop_counter = 0;
$part_counter = 4;
?>
<table>
<form name="partsform" method="post" action="test2.php?authorize=entered" onSubmit="return CheckRB_onsubmit()">
<?php
while($loop_counter < $part_counter)
{
?>
<tr>
<td>
Part<?php echo $loop_counter;?> <input name="Choice" type="checkbox" value="Part <?php echo $loop_counter;?>">
</td>
</tr>
<?php
++$loop_counter;
}
?>
</table>
<input name="parts" type="submit" id="parts" value="Select Part">
</form>
<?php
echo $authorize;
if($authorize == entered)
{
echo"Here We Are.<BR>";
echo $Choice[0]." choice 0<br>";
echo $Choice[1]." choice 1<br>";
echo $Choice[2]." choice 2<br>";
echo $Choice[3]." choice 3<br>";
echo $Choice[4]." choice 4<br>";
echo $Choice[5]." choice 5<br>";
}
?>
</body>
</html>
If the code is modified as shown below, (Choice value with loop counter) the check for checkboxes fails but the output is what I am looking for in that is echoes and carries forward the parts selected:
Part<?php echo $loop_counter;?> <input name="Choice[<?php echo $loop_counter;?>]" type="checkbox" value="Part <?php echo $loop_counter;?>">
Here We Are.
choice 0
choice 1
Part 2 choice 2
choice 3
choice 4
choice 5
How do I form a checkbox array, check for at least one box being checked, yet carry the values forward for utilization later in the scripts?
TIA
Joe