while ($product = mysql_fetch_array($query)) {
'<input type="checkbox" name="'.$product[name].'" value="checked">'
}
while ($product = mysql_fetch_array($query)) {
echo '<input type="checkbox" name="'.$product[name].'" value="checked">';
echo '<input type="hidden" name="hcbox_'.$product[name].'" value="" onChange="javascript:check_cbox(this.form,this,\'hcbox_'.$product[name].'\')">';
}
<script language="JavaScript">
function check_cbox(myform, mycbox, myhfield){
if (document.myform.mycbox.checked){
document.myform.myhfield.value = "";
document.myform.myhfield.value = "TRUE";
return true;
}
else{
document.myform.myhfield.value = "";
document.myform.myhfield.value = "FALSE";
return true;
}
}
// If you want, instead of all that above:
// hpath = document.myform.myhfield;
// if (document.myform.mycbox.checked)?hpath.value = "TRUE" : hpath.value = "FALSE"
</script>
<?
$new_var = 'hcbox_' . $_POST['var'];
if($new_var == "TRUE"){
// Do something
}
else(){ // is FALSE
// Do another thing
}
?>
gesf said:The problem is verifying whether the checkbox is checked or not and giving an 'action' depending on it!
<form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="checkbox" name="checkbox1" value="1" />
<input type="submit" />
</form>
<?php
if(!array_key_exists('checkbox1', $_GET) || empty($_GET['checkbox1'])) {
echo 'The checkbox is not checked!';
} else {
echo 'The checkbox is checked and the value is ' . $_GET['checkbox1'] . '!';
}
?>