Jump to content

Recommended Posts

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?

 

 

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 by nogray
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.