Page 1 of 2

Get text from dynamically created checkboxes (text is populated from database)

Posted: Wed Oct 22, 2014 5:10 pm
by Takis

Hi all

I have check boxes created by a DB Service.
The DB has a table with one column, from where I get the text that will be displayed for the check box.
This works fine.

Now, I have a button.
When I click on the button, I want a javascript to iterate through the checked check boxes and get its text and store it in a local store.

I use various version of the below but I can not get the text

var mobilecheckboxgroup = Apperyio("chkBox_Interests").find(":checked");
var arr = [];
mobilecheckboxgroup.each(function(){
arr.push($(arr).text());
});
localStorage.setItem("lclStg_par1", arr);


Get text from dynamically created checkboxes (text is populated from database)

Posted: Wed Oct 22, 2014 6:14 pm
by Kateryna Grynko

Hi Panagiotis,

To get all checked checkboxes values use the following code: prevar checked = Appery('mobilecheckboxgroup_16')
.find(':checked')
.map(function() {
return this.value;
})/pre


Get text from dynamically created checkboxes (text is populated from database)

Posted: Thu Oct 23, 2014 8:42 am
by Takis

Hi Katerina

I have the dynamic check boxes created fine.
When I put the below code in a button

Code 1--------------------------------------------------
var checked = Appery('mobilecheckboxgroup_16')
.find(':checked')
.map(function() {
return this.value;
});

localStorage.setItem("lclStg_par1", "~" + checked);


the output inside a label, where I put the value of the loacl storage is :
[object Object]

Now if I add in the DB Service mapping another mapping, of my column to also to "value" attribute of the dynamic check box
and
I use this code on a button, all works fine

Code 2-------------------------------------------
var mobilecheckboxgroup = Apperyio("chkBox_Interests").find(":checked");
var arr = [];
mobilecheckboxgroup.each(function(){
arr.push($(arr).text());
});
localStorage.setItem("lclStg_par1", arr);

var checked = [];
Appery("chkBox_Interests").find("input:checked").each(function(){
checked.push($(this).attr("value"));
});

localStorage.setItem("lclStg_par1", arr +"~" + checked);


Is this a correct approach?

Can we make Code 1 to work? Image


Get text from dynamically created checkboxes (text is populated from database)

Posted: Thu Oct 23, 2014 8:58 am
by Takis

SORRY

Correct Code 2 is the below
Code 2---------------------------------
var mobilecheckboxgroup = Apperyio("chkBox_Interests").find(":checked");
var arr = [];
mobilecheckboxgroup.each(function(){
arr.push($(this).attr("value"));
});
localStorage.setItem("lclStg_par1", arr);



Get text from dynamically created checkboxes (text is populated from database)

Posted: Thu Oct 23, 2014 9:03 am
by Evgene Karachevtsev

Hello Panagiotis,

Could you please post your code with tag code for we could be sure that it's not corrupted by this site?


Get text from dynamically created checkboxes (text is populated from database)

Posted: Thu Oct 23, 2014 9:29 am
by Evgene Karachevtsev

Panagiotis,

[quote:]Can we make Code 1 to work? [/quote]
Yes, before saving you should call a get method
prevar checked = Appery('mobilecheckboxgroup_16')
.find(':checked')
.map(function() {
return this.value;
}).get();

localStorage.setItem("lclStg_par1", checked);/pre


Get text from dynamically created checkboxes (text is populated from database)

Posted: Thu Oct 23, 2014 12:36 pm
by Takis

Code 2 - Works fine

code

var mobilecheckboxgroup = Apperyio("chkBox_Interests").find(":checked");
var arr = [];
mobilecheckboxgroup.each(function(){
arr.push($(this).attr("value"));

/code


Get text from dynamically created checkboxes (text is populated from database)

Posted: Thu Oct 23, 2014 12:37 pm
by Takis

The one you posted, stangly does not work. Nothing is written in the label.

var checked = Appery('mobilecheckboxgroup_16')
.find(':checked')
.map(function() {
return this.value;
}).get();
localStorage.setItem("lclStg_par1", checked);


Get text from dynamically created checkboxes (text is populated from database)

Posted: Thu Oct 23, 2014 12:54 pm
by Takis

code
var checked = Appery('mobilecheckboxgroup_16')
.find(':checked')
.map(function() {
return this.value;
}).get();
localStorage.setItem("lclStg_par1", checked);
/code


Get text from dynamically created checkboxes (text is populated from database)

Posted: Thu Oct 23, 2014 6:24 pm
by Evgene Karachevtsev

Hello,

[quote:]The one you posted, stangly does not work.
var checked = Appery('mobilecheckboxgroup_16') [/quote]
Could you please detail, did you replaced "mobilecheckboxgroup_16" with your group name? I see the name "chkBox_Interests" in the working version is used.Also please specify, are there any errors in the browser console?