Page 1 of 1

Checkbox not returning correct value

Posted: Tue Feb 21, 2017 1:18 pm
by Deon

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


Checkbox not returning correct value

Posted: Wed Feb 22, 2017 9:20 pm
by Serhii Kulibaba

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


Checkbox not returning correct value

Posted: Thu Feb 23, 2017 1:59 am
by Deon

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


Checkbox not returning correct value

Posted: Thu Feb 23, 2017 8:43 pm
by Serhii Kulibaba

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

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


Checkbox not returning correct value

Posted: Fri Feb 24, 2017 10:44 am
by Deon

Please explain how I achieve this.

I have 5 checkboxes.

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


Checkbox not returning correct value

Posted: Fri Feb 24, 2017 3:13 pm
by Serhii Kulibaba

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


Checkbox not returning correct value

Posted: Tue Feb 28, 2017 3:02 pm
by Deon

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.


Checkbox not returning correct value

Posted: Wed Mar 01, 2017 11:41 am
by Serhii Kulibaba

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.


Checkbox not returning correct value

Posted: Thu Mar 02, 2017 2:14 pm
by Deon

I will try again.