Jakub
Posts: 0
Joined: Fri Dec 05, 2014 10:53 pm

Checkbox index

Is there a way to get an index of checkbox array?
I am filling a Checkbox from REST service and need to get an index of a clicked checkbox.
This is the code I used for Listview
var li = jQuery(this).closest("li");
var index = li.index('li:not([data-role="list-divider"])');

But is does not work when I change it for checkbox, I get index number that is + 2 than what is should be when clicked (fist item in array should be 0 but index is 2).
var li = jQuery(this).closest("input");
var index = li.index('input');

What am I doing wrong?

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Checkbox index

Hello Jacub,

This code allows to get the checkbox item value:
preApperyio("mobilecheckbox_5").find('input[type="checkbox"]').val();/pre
Also read more here http://devcenter.appery.io/documentat...

Jakub
Posts: 0
Joined: Fri Dec 05, 2014 10:53 pm

Checkbox index

Thanks Alena,

But I need the index value of the checkbox (0,1,2,3,4), as it should correspond to the index of underlying array the checkbox list is built from.

Thank you.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Checkbox index

Hello,

Try this pre$("[name=checkboxgroup]").each(function(index,element){
if (index !==0){
console.log("state= "+ element.checked+" i"+index)
}
})/pre

Return to “Issues”