Welcome to the LimeSurvey Community Forum

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

Defaulting Multiple Short Text Answers based on Checkbox

  • petert
  • petert's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 7 months ago #98856 by petert
I have a survey which asks where you lived during different times of your life, age 18-25, 25-35 etc.

Some people never move. For those people, we would like to have a checkbox on the first screen which is labeled something like "I have lived here my whole life". If this checkbox is checked on the first screen, then additional screens would prefill or default to the City, State, Zip and Country values provided on the first screen.

I have seen numerous forum posts that dance all around this situation, but no direct answers. Any thoughts would be appreciated.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 7 months ago - 10 years 7 months ago #98877 by tpartner
Given the following question/answer codes:

1) "I have lived here my whole life"
- question code - "multiOpt1"
- answer code - "1"

2) "Address when 18-25"
- question code - "address1"
- answer codes - "city", "state", "zip"

3) "Address when 26-35"
- question code - "address2"
- answer codes - "city", "state", "zip"

You could set the default answers for "address2" to:
Code:
{if(multiOpt1_1, address1_city, "")}
Code:
{if(multiOpt1_1, address1_state, "")}
Code:
{if(multiOpt1_1, address1_zip, "")}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 7 months ago by tpartner.
The topic has been locked.
  • petert
  • petert's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 6 months ago - 10 years 6 months ago #99280 by petert
Thanks, that seemed to make sense. However, when I went to do it, the page blew code all over the place. I am using the latest version of 2.00 (130802). See attached screen shot.

Checking the database, the value is properly stored. See attachment.

Reviewing the source code from the page, it appears that Lime is dumping style infomation into the text field's value declaration. Like this:

<input class="text " type="text" size="20" name="39382X132X2265City" id="answer39382X132X2265City" value="<span style='background-color: #eee8aa;'><span title='Conditional processing; if(test,result_if_true,result_if_false)' style='color: blue; font-weight: bold'>if</span>(<span title='Undefined variable' style='border-style: solid; border-width: 2px; border-color: red;'><span title='Undefined variable' style='color: red; font-weight: bold'>RsA1auto_1</span></span>, <span title='[java39382X132X2265City][G:4][Q:23]: City/Town; value={ if(RsA1auto_1, RsB1_City, &quot;&quot;) }' style='color: #996600; font-weight: bold' onclick='window.open("/s/index.php/admin/survey/sa/view/surveyid/39382/gid/132/qid/2265");'>RsB1_City</span>, <span title='' style='color: gray'>""</span>)</span>" onkeyup="checkconditions(this.value, this.name, this.type);" />

Thoughts?
Last edit: 10 years 6 months ago by petert. Reason: Added db attachment
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 6 months ago #99408 by tpartner
That generated code indicates that Expression Manager has a problem - probably with one or more of the variables.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • petert
  • petert's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 6 months ago - 10 years 6 months ago #99550 by petert
Ok, I have studied my variables until my eyes are popping. I created a new, three question survey from scratch using precisely the codes and default invocation calls provided above. Same result, gibberish output. I must be missing something obvious.

No luck getting the xml file to attach, so it can be downloaded here:

www.advanced-design.com/limesurvey_survey_617976.lss.xml
Last edit: 10 years 6 months ago by petert. Reason: no attachment.
The topic has been locked.
  • petert
  • petert's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 6 months ago #99555 by petert
Ok, finally figured it out by reviewing the javascript source code for expression manager.

This code is incorrect and results in the EM throwing a unknown variable error:
Code:
{if(multiOpt1_1, address1_city, "")}
Code:
{if(multiOpt1_1, address1_state, "")}
Code:
{if(multiOpt1_1, address1_zip, "")}


This is the correct code:
Code:
{if(multiOpt1==1, address1_city, "")}
Code:
{if(multiOpt1==1, address1_state, "")}
Code:
{if(multiOpt1==1, address1_zip, "")}
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose