wkilc Posted August 12, 2010 Share Posted August 12, 2010 Greetings once again, My script retrieves variables from a database and pre-populates a form: <input type="text"" name="First" value="<?php echo stripslashes($row['First']); ?>" > Simple to do with text fields, but not as simple for checkboxes: <input type="checkbox" name="Subject" size="27" value="Math" checked> In the past I've used JavaScript to place a check in a checkbox, based on the value in the database. Can anyone show me a simple way to use PHP to place the check if the variable found in the database is in fact "Math"; but leave it it unchecked if the Subject value is empty? As always, thank you! ~Wayne Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 12, 2010 Share Posted August 12, 2010 <input type="checkbox" name="Subject" size="27" value="Math"<?php echo $dbvalue == 'Math' ? ' checked="checked"' : ''; ?> /> Note you should be using checked="checked", not just checked. Quote Link to comment Share on other sites More sharing options...
wkilc Posted August 12, 2010 Author Share Posted August 12, 2010 Bless you! ~Wayne 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.