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 Link to comment https://forums.phpfreaks.com/topic/210508-place-check-in-checkbox/ 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. Link to comment https://forums.phpfreaks.com/topic/210508-place-check-in-checkbox/#findComment-1098358 Share on other sites More sharing options...
wkilc Posted August 12, 2010 Author Share Posted August 12, 2010 Bless you! ~Wayne Link to comment https://forums.phpfreaks.com/topic/210508-place-check-in-checkbox/#findComment-1098362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.