Hello
Please I need help on how to use a range to auto-select a response in another question. Details below
Q1. How old are you? The constraint is .>=14 and .<=24 meaning age should be from 14 to 24
Q2. Is this a child or young adult? Hint child = 14-17years and young adult=18-24years.
option1: Child
option2: Young adult
Now, I want if the age in question 1 is from 14-17, then option 1 should be automatically selected but if the age in question 1 is from 18-24 then option2 should be automatically selected.
I am using xls form.
Thanks
Hello,
You can use a calculation for the select variable, based on the age value.
If( ${Age} >= 18 and ${Age} <= 24, ‘2’, if(${Age} … , ‘1’, “”) )
Adapt ‘2’ and ‘1’ to your choice names.
Even the ands might not be needed, as an if usually evaluates from left to right, stopping with the first true)…
You may also set your second variable to readonly.
If you don’t need to show it to the user,
you might use type calculate or hidden. Or the new feature disabled.
Hello Wroos
Thanks for helping but when I use the provided command under calculation or constraint, I get an error when I try to validate the form. Can you please check it again.
Hello Wroos
This is what worked for me
type -calculate, name-b3i and under calculation I used “if((${Age} < 18), ‘1’, if((${Age} > 17), ‘2’,‘0’))” where “0” is the default as if statements require three arguments.
Then for question 2, which is select_one, the constraint is .=${b3i}, as 1=child (14-17) and 2= young adult (18-24)
Thanks for the help
Hello,
Fine! Avoids additional calculate variable.
I would just add read_only = true for the select.
Question:
Even the ands might not be needed, as an if usually evaluates from left to right, stopping with the first true)… @Kal_Lam: Can you confirm this?
But I like it with the ands (safe and explicit programming).
Did you test your form with the Online validator, please?
Could you share the related part of your form, please, and a screenshot of the Collect problem?
Values of selects are generally stored as string. You should try ‘2’ … for the auto select values in the if expression. It might also be better to use explicit casting for the mathematical comparison. So, I would suggest:
if( number(${A1TScore}) >= 14, ‘5’, … , ‘2’))))
Please, check your form with the Online validator: “Language ‘English (en)’ is missing the survey hint column.” This will result in missing hints for EN.