Jump to content

checkbox and ajax only showing value of on


Orionsbelter

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.