sophielois
Technical User
Hi,
im trying to display the variables from a form which uses checkboxs'. The user is only allowed to select 2 checkboxes.(thankyou guys in the java forum)
How do i grab the 2 values that have been checked and turn them into 2 variables and display them?
the form
add3.php
Im pretty sure i will need to create some kind of loop, but im not sure how to do this.
I need to finish up with something like:
thankyou for any advice you can all offer
Sophx
im trying to display the variables from a form which uses checkboxs'. The user is only allowed to select 2 checkboxes.(thankyou guys in the java forum)
How do i grab the 2 values that have been checked and turn them into 2 variables and display them?
the form
Code:
<script language="javascript" type="text/javascript">
<!-- Script checks that only 2 optional units can be selected
var totalCBs = 0;
var maxChecked = 2;
function keepTrack(c) {
totalCBs += c.checked ? 1 : -1;
enableDisable( c.form, totalCBs == maxChecked );
}
function enableDisable(f, b) {
var e = f.elements;
for (var i = 0; i < e.length; i++) {
if (e[i].type == 'checkbox' && !e[i].checked) e[i].disabled = b;
}
}
function doSubmit() {
if (totalCBs!=maxChecked) {
alert('You need to select ' + maxChecked + ' Optional Units');
return false;
}
return true;
}
-->
</script>
<form action="add3.php" method="post" onsubmit="return doSubmit();">
<input type="checkbox" name="cb1" value="HSC25" onclick="keepTrack(this);" /> HSC25<br />
<input type="checkbox" name="cb2" value="HSC210" onclick="keepTrack(this);" /> HSC210<br />
<input type="checkbox" name="cb3" value="HSC21314" onclick="keepTrack(this);" /> HSC213-14<br />
<input type="checkbox" name="cb4" value="HSC218" onclick="keepTrack(this);" /> HSC218<br />
<input type="checkbox" name="cb5" value="HSC221" onclick="keepTrack(this);" /> HSC221<br />
<input type="checkbox" name="cb6" value="HSC223" onclick="keepTrack(this);" /> HSC223<br />
<input type="checkbox" name="cb7" value="HSC226" onclick="keepTrack(this);" /> HSC226<br />
<input type="hidden" name="userid" value="<?= $userid ?>">
<input type="hidden" name="award" value="<?= $award ?>">
<input type="submit" name="add" value="Proceed">
</form>
add3.php
Code:
<?php
$award= $_POST['award'];
$userid= $_POST['userid'];
$unita= $_POST['cb1'];
$unitb= $_POST['cb2'];
$unitc= $_POST['cb3'];
$unitd= $_POST['cb4'];
$unite= $_POST['cb5'];
$unitf= $_POST['cb6'];
$unitg= $_POST['cb7'];
echo " /* Display the 2 units that were checked*/;
}
?>
Im pretty sure i will need to create some kind of loop, but im not sure how to do this.
I need to finish up with something like:
Code:
<? echo " The user selected unit $unitf and unit $unita"; ?>
thankyou for any advice you can all offer
Sophx