Rui Song Chong
Posts: 0
Joined: Sat Jan 17, 2015 10:51 am

Get checkbox value

Hi,

The checkbox I have is a loop link to the database, which has multiple rows base on the database. I know to get a single checkbox value I can simple use this "Apperyio("checkbox").find('input[type="checkbox"]').val() " but what I have now is a loop.

I have tried this:
var name_arr = [];
checkboxgroup = $('[name="checkboxgroup"]');
for (var i = 0; i < checkboxgroup.length-1; i++) {
name_arr = {"name":Apperyio("checkbox").find('input[type="checkbox"]').val() , "value":Apperyio("checkbox").find('input[type="checkbox"]').val()};
}
Apperyio.storage.nameArray.set(name_arr);

But what I get is only the first checkbox value. How can I get the rest of the checkbox value?
Thanks!

Image

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Get checkbox value

Hi Rui,

Please use following code:

precode

var name_arr = [];
checkboxgroup = $('[name="mobilecheckbox_21"]');
for (var i = 0; i < checkboxgroup&#46;length; i++) { console&#46;log(i);
var currentCheckBox = jQuery(checkboxgroup);
var currentInput = currentCheckBox&#46;find("input");

Code: Select all

 name_arr[i] = { 
     "name": currentInput&#46;val(), 
     "value": currentInput&#46;prop("checked") 
 }; 

}
Apperyio&#46;storage&#46;nameArray&#46;set(name_arr);

/code/pre

Regards.

Rui Song Chong
Posts: 0
Joined: Sat Jan 17, 2015 10:51 am

Get checkbox value

Hi,

How can I modify the code such that only the ticked checkbox value would be store in the array? Sorry I'm bad at coding.

Rui Song Chong
Posts: 0
Joined: Sat Jan 17, 2015 10:51 am

Get checkbox value

Hi,

Thanks for the help!

Return to “Issues”