Alex Rivera | Logout

checkbox is always "on"

Asked 2011-07-06T19:54:52.050
44

Hy!

When Uploadify send the file to the action, I need to know if the checbox is checked or not, so I did:

    $('#uploaded').uploadify({
        'uploader': '/uploadify.swf',
        'cancelImg': '/cancel.png',
        'script': '/Interaction/Upload',
        'multi': true,
        'auto': false,
        'method': 'post',
        'scriptData': {'Checkbox': $('#checkbox').val()},
    });

But I aways get an "on" value. No matter if is checked or not.

can anyone help? Tks.


UPDATE:

I realized that uploadify is getting the checkbox when the page is loaded.This means that if I change the checkbox (or any other type of input) the uploadify will get the initial value, in this case, "checkbox = false".

How can I send a form with uploadify?

Tks.

Edit
Report

2 Answers

21

There is a pretty handy way to check all these element properties like disabled, checked, etc. with the prop function. This also converts it to boolean:

$('#checkbox').prop('checked'); // -> true/false
$('#checkbox').prop('disabled'); // -> true/false
answered 2013-06-23T21:47:36.940
2

I just had the same problem and found this solution:

if($("input[name='yourcheckbox']").is(':checked')) {
   console.log('chb checked');
} else {
   console.log('chb not checked');
}
answered 2012-05-09T12:51:02.700

Your Answer