Orionsbelter Posted February 7, 2014 Share Posted February 7, 2014 Hi there, I'm currently using ajax to update the mysql database via onchange or onclick using checkboxes such as below: <input type="checkbox" name="wac_non_bce" id="wac_non_bce" <?php if($cue_wac_non_bce=="1"){echo"checked='checked'";}?> onchange="changeData(this.value, 'wac_non_bce', '<?php echo"$add_prod_id";?>')" /> The this.value only returns 'on' when checking and unchecking the box; Which is for clear reasons not helpful at all Has any one come across this issue before? Quote Link to comment https://forums.phpfreaks.com/topic/286022-checkbox-and-ajax-only-showing-value-of-on/ Share on other sites More sharing options...
nogray Posted February 7, 2014 Share Posted February 7, 2014 (edited) By default, a checkbox value is "on" regardless if it's checked or not (if set the value property, that value will always be the same if it's checked or not). When a form is submitted and the checkbox is checked, the value is sent with the form. If it's not checked, the value is not sent at all. For your script, you should test the checked property (not value). e.g. changeData(this.checked, ... Also, it's better to use onclick event rather than onchange for older browsers. Edited February 7, 2014 by nogray Quote Link to comment https://forums.phpfreaks.com/topic/286022-checkbox-and-ajax-only-showing-value-of-on/#findComment-1468095 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.