Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Saving Values During Survey Entry to the Token Table

  • cshaw
  • cshaw's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
9 years 3 months ago - 9 years 3 months ago #115550 by cshaw
I am implementing a survey that collects family cancer history in version 2.05. The survey goes through a set of questions for each of the respondent's relatives diagnosed with cancer. After all of the relatives are entered I use some fancy tailoring to present a summary of the relatives for whom history has been entered.

After enabling jumping incrementally, the summary now includes links to the specific page where each relative's history was started in case the respondent needs to make edits to previous answers.

Currently I set the page to jump to manually, but I would prefer to make that link variable so that if more questions are added to the family history I don't need to edit the summary.

To do that I need to capture the value of $("#thispage").attr("value"); when the target page is active, in this case the first female relative (fr1) and recall that value when building the summary links.

The only way I can think of to retain information is to write it to the TOKEN object during the processing and then extracting it again later.

So I added a user defined attribute_4 to my token table "fr1" for the first female relative. With the idea that I would trigger javascript in the document ready code that would check for the question id and if it is the id for the first relative, store the value of: $("#thispage").attr("value"); to the TOKEN object. This is where I get stuck. I am not sure I actually HAVE any way of modifying the TOKEN object during run time.

Does anyone know?

Does anyone have an idea for another approach?

I have some ideas, but they are fairly convoluted, so if I could make this work it would be better. :)

Thanks in advance!
Last edit: 9 years 3 months ago by cshaw. Reason: just making it clearer
The topic has been locked.
  • cshaw
  • cshaw's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
9 years 3 months ago #115555 by cshaw
thisstep not thispage! Oops!
The topic has been locked.
  • cshaw
  • cshaw's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
9 years 3 months ago - 9 years 3 months ago #115557 by cshaw
On the question (fr1reltype) where I need to redirect the survey to I added a tag "<storepage></storepage>" to the question text that triggers a javascript function. The respondent won't see the tag since html disappears. ;)

I then use jquery to populate the tag in the question text with the "thisstep" value, the function is triggered from the document.ready function after page load, but before the respondent sees the page (on most nice browsers!)

Later, when I get to the summary page I can reference the value by pulling the information out of the question text, {fr1reltype.question} ... haven't written the function for pulling the value back out, but that shouldn't be too tricky.

This will work (still have a few steps to go) but makes me think we ought to have a token type table for values the developer wants to set for the whole survey that do not get lost when they move from one page to the next. Sort of a developer clip-board.
Code:
function storePage() { // Store the page index in the document for now
    // boilerplate is a text only question
    if ( $('storepage').length>0 ) {
        var currpage = $("#thisstep").attr('value');
        $("td.be storepage").attr("index",currpage);
  }
}
 
function extractPage() {} // need to write this one still
 
/************************************************************/
$(document).ready(function(){
    storePage()
 
});
Last edit: 9 years 3 months ago by cshaw.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
9 years 3 months ago #115593 by Mazi
Are you using conditions within the survey? Because that could cause problems. If I remember correctly the step variable is related to the previous pages and these can differ if conditions are set to skip questions/pages.

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
  • cshaw
  • cshaw's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
9 years 3 months ago #115626 by cshaw
Hmm, Okay I will test that out. Thanks!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose