Page 1 of 1

Triggering service request on checkbox property

Posted: Mon Nov 04, 2013 10:46 am
by anelezeravla

Hello,
I have a checkbox on my UI. When the users clicks on the checbox, I want a service to be called. If by clicking on the checkbox, the checkbox has gone from unselected to selected, service 1 will be called. If by clicking on the checkbox the checkbox has gone from selected to unselected, service 2 will be called (both services are database services, the second one creating a new object on the database, the first one deleting it).

Therefore, I have created an event upon my checkbox that makes JavaScript run when the user clicks on the checkbox. This is the JS that is executed:

if (Appery('myCheckbox').attr("checked")){

service1.execute();
}
else {
service2.execute();
}

Is this correct? For some reason, only the service2 is performed. The first if clause is never performed. Is there anything I'm not doing properly on the JS?

Thank you.


Triggering service request on checkbox property

Posted: Mon Nov 04, 2013 11:03 am
by Maryna Brodina

Hello! Please check browser console. Are there any errors?


Triggering service request on checkbox property

Posted: Mon Nov 04, 2013 11:14 am
by anelezeravla

No errors on the browser console.
By console.log I see that I'm only entering the else clause. I never enter the if clause, so I assume my JavaScript for checking if the checkbox is checked is wrong ...


Triggering service request on checkbox property

Posted: Mon Nov 04, 2013 1:27 pm
by Maryna Brodina

On Checkbox Value change event run the following code:
prevar $this = $(this);
if ($this.find("input").is(":checked")) {
service1.execute();
} else {
service2.execute();
}/pre


Triggering service request on checkbox property

Posted: Mon Nov 04, 2013 2:37 pm
by anelezeravla

Lovely!