- Posts: 12
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
How to Get/take value from Array(Text) question type in JS.
- Hiccup
- Topic Author
- Offline
- New Member
Less
More
1 year 2 months ago - 1 year 2 months ago #240122
by Hiccup
How to Get/take value from Array(Text) question type in JS. was created by Hiccup
Please help us help you and fill where relevant:
Your LimeSurvey version: [ Version 3.28.17+220627 ]
Own server or LimeSurvey hosting: own
Survey theme/template:
==================
I have one question which used with
Type: Array (Texts)
in this question we have person and person details question into subQuestion.
Question : i am trying to get value of this subquestion in next group but its not availabe.
Can you please help me how to get value in JS in next group question.
Your LimeSurvey version: [ Version 3.28.17+220627 ]
Own server or LimeSurvey hosting: own
Survey theme/template:
==================
I have one question which used with
Type: Array (Texts)
in this question we have person and person details question into subQuestion.
Question : i am trying to get value of this subquestion in next group but its not availabe.
Can you please help me how to get value in JS in next group question.
Last edit: 1 year 2 months ago by Hiccup. Reason: adding More details to understand what actually we trying to say
Please Log in to join the conversation.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12881
- Thank you received: 3964
1 year 2 months ago #240166
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic How to Get/take value from Array(Text) question type in JS.
Usually you only need to use ExpressionScript.
But what exactly do you want to achieve?
Show us by providing a lss export of these questions.
Joffm
But what exactly do you want to achieve?
Show us by providing a lss export of these questions.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Please Log in to join the conversation.
- Hiccup
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
1 year 2 months ago #240184
by Hiccup
Replied by Hiccup on topic How to Get/take value from Array(Text) question type in JS.
I am trying to get value into javascript.
Currently, I am using lime expression to get a single value using
var fnam = "{questioncode_01_fname.shown}";
var age = "{questioncode_01_age.shown}";
like this, we have a total of 10 groups with 5 columns
so i have one textbox where i can get value how many person with me.
in text box we have value like 5.
total 5-time users fill in the details.
i want to get dynamically get values in js.
i.g we have 5 person
for (i=1; i<=5, i++){
fnam[] = "{questioncode_0"+i+"_fname.shown}";
age[] = "{questioncode_0"+i+"_age.shown}";
above value stored into array
}
is that possible in lime?
Currently, I am using lime expression to get a single value using
var fnam = "{questioncode_01_fname.shown}";
var age = "{questioncode_01_age.shown}";
like this, we have a total of 10 groups with 5 columns
so i have one textbox where i can get value how many person with me.
in text box we have value like 5.
total 5-time users fill in the details.
i want to get dynamically get values in js.
i.g we have 5 person
for (i=1; i<=5, i++){
fnam[] = "{questioncode_0"+i+"_fname.shown}";
age[] = "{questioncode_0"+i+"_age.shown}";
above value stored into array
}
is that possible in lime?
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10098
- Thank you received: 3589
1 year 2 months ago #240191
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic How to Get/take value from Array(Text) question type in JS.
Expression manager is parsed on page load so you cannot adjust variable names dynamically.
You will need to declare the JS vars explicitly on page load.
...or...
You will need to declare the JS vars explicitly on page load.
Code:
var aFname = [ "{questioncode_01_fname}", "{questioncode_02_fname}", "{questioncode_03_fname}", "{questioncode_04_fname}", "{questioncode_05_fname}" ] var aAge = [ "{questioncode_01_age}", "{questioncode_02_age}", "{questioncode_03_age}", "{questioncode_04_age}", "{questioncode_05_age}" ]
...or...
Code:
var oAnswers = { 1: {'fname': "{questioncode_01_fname}", 'age': "{questioncode_01_age}"}, 2: {'fname': "{questioncode_02_fname}", 'age': "{questioncode_02_age}"}, 3: {'fname': "{questioncode_03_fname}", 'age': "{questioncode_03_age}"}, 4: {'fname': "{questioncode_04_fname}", 'age': "{questioncode_04_age}"}, 5: {'fname': "{questioncode_05_fname}", 'age': "{questioncode_05_age}"} }
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- Hiccup
- Topic Author
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
1 year 2 months ago - 1 year 2 months ago #240262
by Hiccup
Replied by Hiccup on topic How to Get/take value from Array(Text) question type in JS.
Thank you so much tpartner.
var oAnswers = {
1: {'fname': "{questioncode_01_fname}", 'age': "{questioncode_01_age}"},
2: {'fname': "{questioncode_02_fname}", 'age': "{questioncode_02_age}"},
3: {'fname': "{questioncode_03_fname}", 'age': "{questioncode_03_age}"},
4: {'fname': "{questioncode_04_fname}", 'age': "{questioncode_04_age}"},
5: {'fname': "{questioncode_05_fname}", 'age': "{questioncode_05_age}"}
}
I tried the above option but while adding the Question code into an object that will not working in lime survey source due to lime expression.
lime giving "em" undefine variable error on the screen.
For now, i have to create all fields variables that will be placed/added into an object that works fine but it's a very long method to get all row details.
i.g :
var fnam_01 = "{questioncode_01_fname.shown}";
var fnam_02 = "{questioncode_02_fname.shown}";
var fnam_03 = "{questioncode_03_fname.shown}";
var fnam_04 = "{questioncode_04_fname.shown}";
var fnam_05 = "{questioncode_05_fname.shown}";
var age_01 = "{questioncode_01_age}";
var age_02 = "{questioncode_02_age}";
var age_03 = "{questioncode_03_age}";
var age_04 = "{questioncode_04_age}";
var age_05 = "{questioncode_05_age}";
var oAnswers = {
1: {'fname': fnam_01, 'age': age_01 },
2: {'fname': fnam_02, 'age': age_02 },
3: {'fname': fnam_03, 'age': age_03 },
4: {'fname':fnam_04, 'age': age_04 },
5: {'fname':fnam_05, 'age': age_05}
}
//get your full data by index or for loop
Console.debug(oAnswers[1]);
var oAnswers = {
1: {'fname': "{questioncode_01_fname}", 'age': "{questioncode_01_age}"},
2: {'fname': "{questioncode_02_fname}", 'age': "{questioncode_02_age}"},
3: {'fname': "{questioncode_03_fname}", 'age': "{questioncode_03_age}"},
4: {'fname': "{questioncode_04_fname}", 'age': "{questioncode_04_age}"},
5: {'fname': "{questioncode_05_fname}", 'age': "{questioncode_05_age}"}
}
I tried the above option but while adding the Question code into an object that will not working in lime survey source due to lime expression.
lime giving "em" undefine variable error on the screen.
For now, i have to create all fields variables that will be placed/added into an object that works fine but it's a very long method to get all row details.
i.g :
var fnam_01 = "{questioncode_01_fname.shown}";
var fnam_02 = "{questioncode_02_fname.shown}";
var fnam_03 = "{questioncode_03_fname.shown}";
var fnam_04 = "{questioncode_04_fname.shown}";
var fnam_05 = "{questioncode_05_fname.shown}";
var age_01 = "{questioncode_01_age}";
var age_02 = "{questioncode_02_age}";
var age_03 = "{questioncode_03_age}";
var age_04 = "{questioncode_04_age}";
var age_05 = "{questioncode_05_age}";
var oAnswers = {
1: {'fname': fnam_01, 'age': age_01 },
2: {'fname': fnam_02, 'age': age_02 },
3: {'fname': fnam_03, 'age': age_03 },
4: {'fname':fnam_04, 'age': age_04 },
5: {'fname':fnam_05, 'age': age_05}
}
//get your full data by index or for loop
Console.debug(oAnswers[1]);
Last edit: 1 year 2 months ago by Hiccup.
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10098
- Thank you received: 3589
1 year 2 months ago #240270
by tpartner
Or:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic How to Get/take value from Array(Text) question type in JS.
Sorry, I was working from my phone. To avoid ExpressionScript errors, you need to insert a space or line-break after all opening curly braces and before closing braces that are not used by ExpressionScript.I tried the above option but while adding the Question code into an object that will not working in lime survey source due to lime expression. lime giving "em" undefine variable error on the screen.
Code:
var oAnswers = { 1: { 'fname': "{questioncode_01_fname}", 'age': "{questioncode_01_age}" }, 2: { 'fname': "{questioncode_02_fname}", 'age': "{questioncode_02_age}" }, 3: { 'fname': "{questioncode_03_fname}", 'age': "{questioncode_03_age}" }, 4: { 'fname': "{questioncode_04_fname}", 'age': "{questioncode_04_age}" }, 5: { 'fname': "{questioncode_05_fname}", 'age': "{questioncode_05_age}" } }
Or:
Code:
var oAnswers = { 1: { 'fname': "{questioncode_01_fname}", 'age': "{questioncode_01_age}" }, 2: { 'fname': "{questioncode_02_fname}", 'age': "{questioncode_02_age}" }, 3: { 'fname': "{questioncode_03_fname}", 'age': "{questioncode_03_age}" }, 4: { 'fname': "{questioncode_04_fname}", 'age': "{questioncode_04_age}" }, 5: { 'fname': "{questioncode_05_fname}", 'age': "{questioncode_05_age}" } }
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.