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

This forum contains topics that were moved from Get Satisfaction
Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

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

Post 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);

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

Post 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

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

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

Post 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

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

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

Post 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);


Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

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

Post 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?

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

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

Post 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

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

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

Post 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

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

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

Post 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);

Takis
Posts: 0
Joined: Wed Oct 22, 2014 5:10 pm

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

Post by Takis »

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

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

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

Post 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?

Post Reply