Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Dynamically alter answer options based on server data and previous question

Dynamically alter answer options based on server data and previous question 1 Jahr 4 Monate her #95752

  • Rallard
  • Rallards Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 5
  • Karma: 0
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!
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Dynamically alter answer options based on server data and previous question 1 Jahr 4 Monate her #95775

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4207
  • Dank erhalten: 791
  • Karma: 360
Tried...and variants, but they all change fields of the class...
Try:
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: Rallard

Dynamically alter answer options based on server data and previous question 1 Jahr 4 Monate her #95785

  • Rallard
  • Rallards Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 5
  • Karma: 0
Great thanks alot Tony!

The text got updated with what you put. Also I found and tried the following which also worked:
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
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.138 Sekunden
Donation Image