I have the code below that works as page.html and as page.php. It counts and verifies/limits the number of checked boxes to within a range of 2-4 only. I was fine until I had to output the values of the checked boxes as comma delimited so another PHP script can use them. Do I need to change the JS to PHP in order to output the checked ckb values or do I use another function loop within the script and output the values there?
<form name=form1 onsubmit="chkcontrol()" method=post>
<div><input type=checkbox name=ckb value=B117>Add to Compare</div>
<div><input type=checkbox name=ckb value=264B>Add to Compare</div>
<div><input type=checkbox name=ckb value=KVS1>Add to Compare</div>
<div><input type=checkbox name=ckb value=1664>Add to Compare</div>
<div><input type=checkbox name=ckb value=PA03>Add to Compare</div>
<input type="submit" value="Compare" class="fsSubmitButton" />
</form>
<script type="text/javascript">
function chkcontrol(j) {
var total=0;
for(var i=0; i < document.form1.ckb.length; i++){
if(document.form1.ckb[i].checked){
total =total +1;}
}
if (total < 2 || total > 4) {
alert("Please select 2 - 4 models to Compare")
return false;
}
/*alert("View your Compare Table below")*/
for loop if...ckb.checked ?
output(ckb[])
}
</script>
Aucun commentaire:
Enregistrer un commentaire