anelezeravla
Posts: 0
Joined: Tue Oct 01, 2013 12:00 pm

Triggering service request on checkbox property

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Triggering service request on checkbox property

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

anelezeravla
Posts: 0
Joined: Tue Oct 01, 2013 12:00 pm

Triggering service request on checkbox property

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Triggering service request on checkbox property

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

Return to “Issues”