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
  • Rallard's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago #95752 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!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 10 months ago #95775 by tpartner

Tried...and variants, but they all change fields of the class...

Try:
Code:
var text1 = "Travel for " + multiplier1 * userTime + " mins at €" + multiplier2 * userCost + ".";
 
$('label[for="answer{SGQ}1"]').text(text1);

...but I need to record what the respondent saw when answering the question...

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.

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
  • Rallard's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago #95785 by Rallard
Great thanks alot Tony!

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.

Lime-years ahead

Online-surveys for every purse and purpose