jrpelt Posted April 12, 2013 Share Posted April 12, 2013 <input id="auction" type="checkbox" name="auction" value="Yes" /> When I submit a checkbox or dropdown the selections don't show. Would someone mind helping me, I'm sure it's simple I just don't know how to go about this. Quote Link to comment Share on other sites More sharing options...
jrpelt Posted April 12, 2013 Author Share Posted April 12, 2013 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 ?>/> Quote Link to comment Share on other sites More sharing options...
jrpelt Posted April 12, 2013 Author Share Posted April 12, 2013 <?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. Quote Link to comment Share on other sites More sharing options...
subhomoy Posted April 12, 2013 Share Posted April 12, 2013 you can also do it in this way... <input id="auction" type="checkbox" name="auction" value="Yes" checked="checked"/> Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 12, 2013 Share Posted April 12, 2013 for drop-down select menus output selected="selected" inside the <option > tag you want to be selected. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.