Iluvatar+ Posted March 16, 2012 Share Posted March 16, 2012 Does anyone no a way to post a unchecked checkbox value? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 16, 2012 Share Posted March 16, 2012 You would need to put a hidden field in the form before the checkbox and use the same name as the checkbox - <form method='post' action=''> <input type='hidden' name='some_name' value='off'> <input type='checkbox' name='some_name'> <input type='submit'> </form> Quote Link to comment Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 Why? A checkbox is a boolean - it's either on or it's off. Logically, then, if it is not "checked" it is safe to assume it is "unchecked". Quote Link to comment Share on other sites More sharing options...
Iluvatar+ Posted March 16, 2012 Author Share Posted March 16, 2012 Yea but if it's returned false then teh value wont post and i need the 0 value in order to update a permission record in my table. Quote Link to comment Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 So do something like $check = isset($_POST['checkbox']) ? 1 : 0; If the checkbox is checked it will be "1", if not it will be "0". Quote Link to comment Share on other sites More sharing options...
Iluvatar+ Posted March 16, 2012 Author Share Posted March 16, 2012 Thank you, i used hidden text boxes and used jquery to toggle it's value on a ifChecked event in the end. Quote Link to comment Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 What if they have Javascript disabled? Then it will always be "off". Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 16, 2012 Share Posted March 16, 2012 So do something like $check = isset($_POST['checkbox']) ? 1 : 0; If the checkbox is checked it will be "1", if not it will be "0". What he said. Using JavaScript is a really poor solution. There are sometimes hurdles when dealing with checkboxes - such as when you have a series of checkboxes to EDIT existing values. But, there are tried and true methods of handling those. 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.