- Posts: 23
- Thank you received: 0
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
- Topic Author
- Offline
- Junior Member
Less
More
4 months 1 week ago #253451
by nadica123
Validating a numerical input using numerical input answer from previous question was created 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.
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
4 months 1 week ago - 4 months 1 week ago #253452
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Validating a numerical input using numerical input answer from previous question
Something like this in the question validation equation:
- manual.limesurvey.org/ExpressionScript_-_Presentation/en
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
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12942
- Thank you received: 3979
4 months 1 week ago #253454
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Validating a numerical input using numerical input answer from previous question
And there is the setting "Maximum value" in the "Input" menu.
Just enter the code yoof ur previous question.
Joffm
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 0
4 months 1 week ago #253709
by nadica123
Replied by nadica123 on topic Validating a numerical input using numerical input answer from previous question
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.
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
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12942
- Thank you received: 3979
4 months 1 week ago #253712
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Validating a numerical input using numerical input answer from previous question
Always better to provide a lss export.
Makes everything clearer and easier for us.
Joffm
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 0
4 months 1 week ago - 4 months 1 week ago #253716
by nadica123
Replied by nadica123 on topic Validating a numerical input using numerical input answer from previous question
Thank you for the quick reply, here is the file.
Last edit: 4 months 1 week ago by nadica123.
Please Log in to join the conversation.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12942
- Thank you received: 3979
4 months 6 days ago #253753
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Validating a numerical input using numerical input answer from previous question
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)
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
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)
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
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 0
4 months 6 days ago #253791
by nadica123
Replied by nadica123 on topic Validating a numerical input using numerical input answer from previous question
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.
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
4 months 6 days ago #253795
by DenisChenu
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.
Replied by DenisChenu on topic Validating a numerical input using numerical input answer from previous question
@Joffm didn't add NAOK to the value : manual.limesurvey.org/Expression_Manager#Usage_of_NAOKHi,
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.
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
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12942
- Thank you received: 3979
4 months 6 days ago #253800
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Validating a numerical input using numerical input answer from previous question
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
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.