Jump to content

How to keep checkboxes checked and dropdown selections on submit


jrpelt

Recommended Posts

this works to keep it checked but on first load I get the undefined index error.

<?php
// If the box was checked, keep it checked
    if ( isset($_POST['auction']) && $_POST['auction'] == 'Yes' ) {
         $checked = 'checked="checked"';
    } else {
         $checked = '';
    }
?>

<input id="auction" type="checkbox" name="auction" value="Yes" <?php echo $checked ?>/>
<?php
// If the box was checked, keep it checked
    if ( isset($_POST['auction']) && $_POST['auction'] == 'Yes' ) {
         $checked = 'checked="checked"';
    } else {
         $checked = '';
    }
?>

<input type="hidden" value="No" name="auction" /><!-- Added this to get rid of undefined index problem -->
<input id="auction" type="checkbox" name="auction" value="Yes" <?php echo $checked ?>/>

Okay so that took care of my undefined index problem and I now have a checkbox that remains checked after submitting the form. Now I want my drop down menus to retain their selected values.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.