Welcome to the LimeSurvey Community Forum

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

Validating a numerical input using numerical input answer from previous question

  • nadica123
  • nadica123's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 months 1 week ago #253451 by nadica123
Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting:
Survey theme/template:
==================
(Write here your question/remark)

Hello,

I would like to validate a numerical input on a question based on the numerical answer of the previous question. For example if an answer to a question is 5 it can't be greater than 4 in the next one. I found the regular expression and the Question validation equation in the settings, but I am not sure if I can add the previous question answer to it or how to exactly.

Thank you.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 months 1 week ago - 4 months 1 week ago #253452 by tpartner
Something like this in the question validation equation:

Code:
is_empty(this) OR this < Q1

- manual.limesurvey.org/ExpressionScript_-_Presentation/en

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 months 1 week ago by tpartner.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 months 1 week ago #253454 by Joffm
And there is the setting "Maximum value" in the "Input" menu.
Just enter the code yoof ur previous question.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • nadica123
  • nadica123's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 months 1 week ago #253709 by nadica123
Hello,

I am trying to add a condition where G01Q06 is a question that shows up only if another question before is answered with yes. So I have this equation where it checks if it's not empty the input value can be <= from the two questions input otherwise if it's empty the input only needs to be < than the previous answer.

if( !is_empty(G01Q06), this <= G01Q05 - G01Q06, this < G01Q05)

I'm having an issue where the question G01Q06 doesn't have an input value but the condition doesn't seem to work, as it's not recongnizing that the G01Q06 is empty actually.

I also tried like this, but no luck.

(!is_empty(G01Q06) && this <= G01Q05 - G01Q06) OR (is_empty(G01Q06) && this <G01Q05)

Would appreciate the help, thanks.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 months 1 week ago #253712 by Joffm
Always better to provide a lss export.
Makes everything clearer and easier for us.

Joffm 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • nadica123
  • nadica123's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 months 1 week ago - 4 months 1 week ago #253716 by nadica123
Thank you for the quick reply, here is the file. 

File Attachment:

File Name: limesurvey...1954.lss
File Size:49 KB
Last edit: 4 months 1 week ago by nadica123.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 months 6 days ago #253753 by Joffm
Hi,
I wrote before:
No need to use validation equations.
Sufficient to set the max value

"children"


"hh+18"

Here it is
if(!is_empty(G01Q06),G01Q05-G01Q06, G01Q05-1)

 

File Attachment:

File Name: limesurvey...9541.lss
File Size:49 KB


Why is it necessary to ask "Do you have children Y/N"?
Just ask for the number of children (if there are no, the respondent enters "0")
You avoid the IF and the max value of 18+hh is Q05-Q06.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • nadica123
  • nadica123's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 months 6 days ago #253791 by nadica123
Hi,

I need to have the Y/N question since that is required in the survey. I am having an issue with the code you've suggested when the answer is no on that question(so there is no value in G01Q06) and then the condition doesn't work.

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 months 6 days ago #253795 by DenisChenu

Hi,

I need to have the Y/N question since that is required in the survey. I am having an issue with the code you've suggested when the answer is no on that question(so there is no value in G01Q06) and then the condition doesn't work.
 
@Joffm didn't add NAOK to the value : manual.limesurvey.org/Expression_Manager#Usage_of_NAOK

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.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 months 6 days ago #253800 by Joffm
Correct, "NAOK" was missing.

One other glitch: the max. value of Q06 should be "Q05.1"
And in my opinion better to check for "Q08==2" instead of "is_empty(Q06)"

if(G01Q08==1,G01Q05-G01Q06.NAOK, G01Q05)

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose