- Posts: 5
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Dynamically alter answer options based on server data and previous question
- Rallard
- Topic Author
- Offline
- New Member
Less
More
10 years 10 months ago #95752
by Rallard
Dynamically alter answer options based on server data and previous question was created by Rallard
Hi,
I've looked through the fora, but I can't find help. I am doing a Stated Preference Survey which means that I am calculating Answer options based on previous responses as well as a survey design file which is on the server.
I have already coded the previous questions which capture information like costs and times for trips made. I have also used AJAX to read some numbers from a server file that will be used as multipliers for the data entered by the users.
_________
1) What I want to do now is offer the respondent four options using a Radio List for each question, but I want to show them options that are calculated like:
"Travel for " + multiplier1 * userTime + " mins at €" + "multiplier2 * userCost + "."
I currently have the server data read into the question sourcecode, how do I dynamically change the Answer labels to reflect what I need?
Tried:
$('#answer{SGQ}1').val('new text');
and variants, but they all change fields of the class rather than the visible label itself (for which I have a default text).
_________
2) I would like to have the answer order randomised, which I suppose I can do with Advanced Options of the Question, but I need to record what the respondent saw when answering the question, which means that I want to store in the DB the exact text shown for each answer for each of the questions (or at least, the multipliers used for that respondent), as well as the order shown. How do I do this?
Ryan
LS Version 2.00+ Build 130428
PS - Limesurvey is pretty awesome, good job!
I've looked through the fora, but I can't find help. I am doing a Stated Preference Survey which means that I am calculating Answer options based on previous responses as well as a survey design file which is on the server.
I have already coded the previous questions which capture information like costs and times for trips made. I have also used AJAX to read some numbers from a server file that will be used as multipliers for the data entered by the users.
_________
1) What I want to do now is offer the respondent four options using a Radio List for each question, but I want to show them options that are calculated like:
"Travel for " + multiplier1 * userTime + " mins at €" + "multiplier2 * userCost + "."
I currently have the server data read into the question sourcecode, how do I dynamically change the Answer labels to reflect what I need?
Tried:
$('#answer{SGQ}1').val('new text');
and variants, but they all change fields of the class rather than the visible label itself (for which I have a default text).
_________
2) I would like to have the answer order randomised, which I suppose I can do with Advanced Options of the Question, but I need to record what the respondent saw when answering the question, which means that I want to store in the DB the exact text shown for each answer for each of the questions (or at least, the multipliers used for that respondent), as well as the order shown. How do I do this?
Ryan
LS Version 2.00+ Build 130428
PS - Limesurvey is pretty awesome, good job!
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10630
- Thank you received: 3696
10 years 10 months ago #95775
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 Dynamically alter answer options based on server data and previous question
Try:Tried...and variants, but they all change fields of the class...
Code:
var text1 = "Travel for " + multiplier1 * userTime + " mins at €" + multiplier2 * userCost + "."; $('label[for="answer{SGQ}1"]').text(text1);
I think you will need to load the generated text from above into a following multiple-text question. You can hide this question with CSS or JavaScript....but I need to record what the respondent saw when answering the question...
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Rallard
The topic has been locked.
- Rallard
- Topic Author
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
10 years 10 months ago #95785
by Rallard
Replied by Rallard on topic Dynamically alter answer options based on server data and previous question
Great thanks alot Tony!
The text got updated with what you put. Also I found and tried the following which also worked:
I haven't tried the question text saving as yet, but that idea seems simple enough that it should work.
Ryan
The text got updated with what you put. Also I found and tried the following which also worked:
Code:
document.getElementById('javatdbSSSSXGGXQQA').getElementsByTagName("label")[0].innerHTML = text1;
I haven't tried the question text saving as yet, but that idea seems simple enough that it should work.
Ryan
The topic has been locked.