Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Checkbox not returning correct value

Hi

I am checking to see if a checkbox is NOT checked with this code where cbi is the checkbox item ...

if (Apperyio("cbi").find("input").not(":checked")) {
alert('True');
}
else {
alert('False');
}

It returns True, whether the checkbox is ticked or not.

However when I check to see if the checkbox IS checked it returns the correct values. True when checked and False when not checked.

if (Apperyio("cb2").find("input").is(":checked")) {
alert('True');
}
else {
alert('False');
}

This is not logical.
I need to return TRUE if a checkbox is NOT checked and FALSE if it is checked. Please can you clarify why this is not working as it should.
Thank you

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Checkbox not returning correct value

Hello Deon,

Please use a JS code below to check, is checkbox checked or not:
preif ($("[name=mobilecheckbox_56] input").is(":checked")){
alert("True");
} else {
alert("False");
}/pre

here mobilecheckbox_56 - name of your checkbox

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Checkbox not returning correct value

Hi Sergiy
Thank you for your reply.

Please see my question again.

"I am checking to see if a checkbox is NOT checked...."

I need to return True if NOT checked.

In your case Checking if a Checkbox is checked returns True. This does not work in my case where I have multiple checkboxes and want to perform a task only if all of them have NOT been checked.

Thank you

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Checkbox not returning correct value

You can just change alert messages. What is wrong with it?

Do you need to check these values from checkboxes, generated with a mapping?

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Checkbox not returning correct value

Please explain how I achieve this.

I have 5 checkboxes.

If all 5 checkboxes are unchecked then do something
else
all is ok

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Checkbox not returning correct value

Please unite these conditions with "&&" so your JS will be:

preif(!$("[name=mobilecheckbox_64] input").is(":checked") &&
!$("[name=mobilecheckbox_65] input").is(":checked") &&
!$("[name=mobilecheckbox_66] input").is(":checked") &&
!$("[name=mobilecheckbox_67] input").is(":checked") &&
!$("[name=mobilecheckbox_68] input").is(":checked")){
// do something
}/pre

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Checkbox not returning correct value

That wont work. It must do something ONLY if ALL checkboxes are NOT checked.

In your scenario, even if only one is not checked it will return FALSE, which is not what I want.

Why does your NOT operator not work? The logic can only work if IS is replaced with NOT.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Checkbox not returning correct value

Yes, you can use a method "not" here, it was just a fix of exist JS code.

It returns TRUE if ALL checkboxes are UNCHECKED, please check it again.

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Checkbox not returning correct value

I will try again.

Return to “Issues”