Welcome to the LimeSurvey Community Forum

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

How to access radio button type sub-answers individualy?

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 6 months ago - 1 year 6 months ago #244852 by linuxhooligan
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.1.6+230703
Own server or LimeSurvey hosting: VPS
Survey theme/template: Default
==================

Hi.

We are creating multiple choice and single choice questions similar to this:

QUESTION: You and your collaborator have different views on how to solve a problem, how do you communicate your viewpoints to them?
[ ] TRAIT01 - I leave it be.
[ ] TRAIT02 - agree to do it their way.

QUESTION: Your collaborator made a rude joke during a meeting, and it made you look bad in front of the team. You:
[ ] TRAIT01 - Apologise on their behalf.
[ ] TRAIT02 - Talk to them after the fact.

Since we are testing for personality traits, we need to assign individual value to each trait and then at the end of the survey sum all the values each trait across any number multiple or single choice questions as follows:

* TRAIT01
* TRAIT02

With check boxes, we can reference individual answers and values using the following syntax:  sum(if(G01Q01_acc.NAOK == "Y", 1, 0), if(G01Q02_acc.NAOK == "Y", 1, 0), ... if(G01Q06_acc04.NAOK == "Y", 1, 0))

How is this done using radio buttons?  I have checked the documentation but I must have missed it.  Google has not been able to help me narrow down the syntax either.

Thanks.




 
Last edit: 1 year 6 months ago by linuxhooligan.

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 6 months ago - 1 year 6 months ago #244870 by linuxhooligan
Okay, so I made a mistake in my understanding of how radio buttons work. Answer:

1) Single choice (radio buttons) - can only have one answer / value.

2) You don't access the subquestion, you simply access the question and check either the value or the question. So in this case we can:

Display the actual single choice (radio button) question: {QUESTIONCODE.question}

Display the select single choice (radio button): {QUESTIONCODE.shown}

Display the single choice (radio button) code: {QUESTIONCODE.code}

In our case, since each radio button choice has a different CODE we will have to use logic to assign a value and them sum that value. This will probably use a lot of if statements.

Does anyone know of a code sample that can check for the CODE of a radio button answer, assign a value based on code and then sum those values up per CODE?

Any suggestions are welcome.
Last edit: 1 year 6 months ago by linuxhooligan.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago - 1 year 6 months ago #244871 by holch
Funny enough, usually people have problems with the multiple answer questions, not with the single choice. :-)

With single choice it would be just something like "if(G01Q02=1)" etc.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
Last edit: 1 year 6 months ago by holch.

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 6 months ago - 1 year 6 months ago #244877 by linuxhooligan
Ha! I love to make the hard things difficult and the easy things hard.

And, here is how we can actually check the answer CODE of a single choice (radio) field and assign a value to it and then sum the values up.

{sum(if(QUESTIONCODE01.code=="SomeCodeValue",1,0),if(QUSTIONCODE02.code=="SomeCodeValue",1,0))}

For newbs looking this one up, it basically just says, check the code of each question, if the value is"SomeCodeValue" assign a value of 1 otherwise assign a value of 0.

Expression engine is really quite powerful.

Thanks all.
Last edit: 1 year 6 months ago by linuxhooligan.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago #244878 by holch
By the way, while I don't recommend to use the Assessment feature, using the assessment value can save you some time with single choice questions. Activate the assessment feature, but do not use it except for the assessment values.

You can then give each of your answer options a normal answer code plus an assessment value. E.g. in your case you would give all answer options a 0 except for one where you give 1.

Then you can just sum it up without the "if" check.

to acess the assessment value, use QUESTIONCODE01.value

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The following user(s) said Thank You: linuxhooligan

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago - 1 year 6 months ago #244879 by holch
Thinking again, in your specific case my solution with ".value" wouldn't work, as depending on the trait you are summing up different values for each answer option.

The solution still can be handy in other situations, but here it wouldn't work.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
Last edit: 1 year 6 months ago by holch.
The following user(s) said Thank You: linuxhooligan

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 6 months ago - 1 year 6 months ago #244880 by Joffm
And using the function "countifop" you shorten it to

single question:
{countifop("==","acc",Q1.NAOK,Q2.NAOK,...))}

multiple question:
{countifop("==","Y",Q1_acc.NAOK,Q2_acc.NAOK,...))}

Here I used "acc" as code and subquestion code. You'd better use numerical codes

[url] www.limesurvey.org/manual/ExpressionScri...mplemented_functions [/url]

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 6 months ago by Joffm.
The following user(s) said Thank You: linuxhooligan

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 6 months ago #244882 by linuxhooligan
Ahhhh ... right. Okay, very intersting. Will look all of that up. Thanks for the doc link, that's great.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose