I’m trying to make checkbox work like radiobutton with on/off value being passed to $info.
This code works fine, variable info is sent and read through GET
<?php if (empty($info)) { $info='on'; } ?>
<input type="checkbox" name="info" value="<?php if ($info=='on'){ echo "off"; } else { echo "on"; } ?>" onchange="this.form.submit()" />
adding this :
**<?php if (!empty($info)){ echo 'checked="checked"'; } ?>**
<input type="checkbox" name="info" value="<?php if ($info=='on'){ echo "off"; } else { echo "on"; } ?>" <?php if (!empty($info)){ echo 'checked="checked"'; } ?> onchange="this.form.submit()" />
breaks something – GET variables are not sent or read, value is always OFF. Why ? It makes not sense.Adding checked=”checked” to checkbox makes GET variables for this checkbox not being sent.
When a checkbox is NOT checked, the value will not be submitted. So when you uncheck it, the onchange will trigger but nothing gets submitted because the box is not checked. Here is a solution: