Javascript and CheckBox component

Posted by laurent KIEFFER on 31-Jul-2014 10:24

Hi

i am looking to get the value of a checkbox component....like

$('input[name=check_box_group]:checked').val(); 

It does return "undefined".... perhaps i have to make a break but.... what should be the syntax if this is not correct ?

All Replies

Posted by Phillip Molly Malone on 31-Jul-2014 22:29

Hey Mate,

Try this (assuming you have a checkbox group with just with item in it and that group is called "mobilecheckboxgroup_2"):

-------------------

var checkbox_arr = Appery("mobilecheckboxgroup_2").find("input");

var checked = $(checkbox_arr [0]).is(":checked");

console.log("checked is " + checked);

===================

Hope this helps

Posted by Ricardo Perdigao on 31-Jul-2014 22:49

There is probably 10 different ways to do this ... Here is how I do it:

On the value change of the mobilecheckboxgroup:

var str = '';

$('input[name="mobilecheckboxgroup"]').each(function(){

   if (this.checked == true) {

       str    += $(this).val() + ',';

 }

});

localStorage.setItem('CheckedList',str''));

This will should work if you have one checkbox or multiple checkboxes on the group.  The localStorage "CheckedList" will have a list of of all the Checkboxes that were checked.

Regards,

Ricardo

This thread is closed