Hey!
I want to use a Checkbnox where a user can select something
But I want the checkbox to stay checked if the user reloads the page.
It would check wether to check it from a mysql dat
How would I do this?
Checkboxes & MySQL
Started by Bioshox, May 20 2010 01:26 AM
3 replies to this topic
#1
Posted 20 May 2010 - 01:26 AM
|
|
|
#2
Posted 20 May 2010 - 03:27 AM
Like:
This will make it checked when page is reloaded for form submission. Though if you want it to still be checked if page is just reloaded without any form submission, then it'll require AJAX or might be able to be done with normal javascript as well. Let me know if you need that done =].
<input type='checkbox' name='myCheckbox' value='myValue' <?php if($_POST['myCheckbox'] == 'myValue') { echo "checked"; } ?>>
This will make it checked when page is reloaded for form submission. Though if you want it to still be checked if page is just reloaded without any form submission, then it'll require AJAX or might be able to be done with normal javascript as well. Let me know if you need that done =].
#3
Posted 20 May 2010 - 09:38 AM
by definition, the attribute checked shall have value checked, so it becomes
<input type='checkbox' name='myCheckbox' value='myValue' <?php if($_POST['myCheckbox'] == 'myValue') { echo 'checked="checked"'; } ?>>
<input type='checkbox' name='myCheckbox' value='myValue' <?php if($_POST['myCheckbox'] == 'myValue') { echo 'checked="checked"'; } ?>>
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#4
Posted 20 May 2010 - 01:05 PM
Hmm I see, for me just adding 'checked' to the tag worked fine, but what you say might be more correct.


Sign In
Create Account


Back to top









