Welcome to the LimeSurvey Community Forum

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

Using hidden equation question to autofill an answer

  • SurveyDennis
  • SurveyDennis's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 6 months ago #127412 by SurveyDennis
Hi,

I am using the below instruction from the manual - Using hidden equation question to autofill an answer

Limesurvey Autofill

All working fine, except in my exmample it will always autofill the last option.
Even if I have selected a different answer then > 44.

I assume I just have a wrong typo somewhere or using the && wrong. But I don't see it, anyone that can help?
Code:
{DummyAge=if(Demographie2.NAOK < 16, DummyAge="A", if(Demographie2.NAOK > 15 &amp;&amp; Demographie2.NAOK < 30, DummyAge="B", if(Demographie2.NAOK > 29 &amp;&amp; Demographie2.NAOK < 45, DummyAge="C", if(Demographie2.NAOK > 44, DummyAge="D" ))))}

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 6 months ago - 8 years 6 months ago #127413 by DenisChenu
Hi,

Seems to have an error in the manual ....
Doing
Code:
{if(1,QCODE="A",QCOE="B")}
don't work.
Code:
{QCODE=if(1,"A","B")}
work.

Then :
Code:
{DummyAge=if(Demographie2.NAOK < 16, "A", if(Demographie2.NAOK > 15 &amp;&amp; Demographie2.NAOK < 30, "B", if(Demographie2.NAOK > 29 &amp;&amp; Demographie2.NAOK < 45, "C", if(Demographie2.NAOK > 44, "D" ))))}
does the trick.

[strike]If you have some time to update the manual after testing[/strike]. It can be great :).
Done, but if you can improve it ;)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 8 years 6 months ago by DenisChenu.
The following user(s) said Thank You: SurveyDennis
The topic has been locked.
  • SurveyDennis
  • SurveyDennis's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 5 months ago - 8 years 5 months ago #127577 by SurveyDennis
Replied by SurveyDennis on topic Using hidden equation question to autofill an answer
Sorry very late response, thank you for looking into this, need to test it later this week.

I used a different way to make it working, but your solution is better ofcourse:

Be SurveyFriendly too! Fight against boring surveys! www.SurveyFriendly.com
Last edit: 8 years 5 months ago by DenisChenu. Reason: No need link
The topic has been locked.
More
7 years 2 months ago #147665 by neraunzaran
Hi guys, i'm kind of newbie on programming serious on LS.

I'm been trying to perform the same trick than SurveyDennis, i've already consult the link he provided.

Also tried to follow Denis Chenu recomendation, but i'm doing something wrong. :(

This is my equation:

{ QF2= if(QF1.NAOK<18, "1" if(QF1.NAOK>17 && QF1.NAOK<24, "2" if(QF1.NAOK>23 && QF1.NAOK<30, "3" if(QF1.NAOK>29 && QF1.NAOK<36, "4" if(QF1.NAOK>35 && QF1.NAOK<43, "5" if(QF1.NAOK>42 && QF1.NAOK<50, "6" if(QF1.NAOK>49 && QF1.NAOK<58, "7" if(QF1.NAOK>57 && QF1.NAOK<65, "8" if(QF1.NAOK>64, "9"))))))))) }

where QF1-> ask for age. then i need to generate 9 different categories.

Could you guide me on what i'm doing wrong. If you can provide a file with example, i will be in great debt with you.

Thanks in advance and best regards from mexico.
The topic has been locked.
  • elissa
  • elissa's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 2 months ago #147670 by elissa
Hi,
At first glance there are commas (,) missing before successive "if" commands.
Cheers

Elzbieta Lesinska
LS voluntary Polish translator and supervisor
The following user(s) said Thank You: DenisChenu
The topic has been locked.
More
7 years 2 months ago #147671 by Ben_V

elissa wrote: At first glance there are commas (,) missing before successive "if" commands.


Good catch Elissa...

I think it could be something like:
Code:
{ QF2 =
  if (QF1.NAOK < 18, "1",
           if (QF1.NAOK > 17 &amp;&amp; QF1.NAOK < 24, "2",
              if (QF1.NAOK > 23 &amp;&amp; QF1.NAOK < 30, "3",
                  if (QF1.NAOK > 29 &amp;&amp; QF1.NAOK < 36, "4",
                      if (QF1.NAOK > 35 &amp;&amp; QF1.NAOK < 43, "5",
                          if (QF1.NAOK > 42 &amp;&amp; QF1.NAOK < 50, "6",
                              if (QF1.NAOK > 49 &amp;&amp; QF1.NAOK < 58, "7",
                                  if (QF1.NAOK > 57 &amp;&amp; QF1.NAOK < 65, "8", "9"))))))))
}

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose