# Constraints between an integer and multiple choices

Hi everyone,
I am having a problem like this: I want to put a constraint between an
integer input and a choice in multiple choice question.

Q1. How much do you spend on food everyday? _________

Q2. Please select the range ?

a. Less than 10usd
b. Between 10usd and 20usd
c. More than 20usd

I want to put a constraint that warn the surveyors in case they input 50usd
and select a or b. Is there anyway to do that.

Thank you very much.

Hi, Tony.
Try this (assuming that your Q2 is select_one question):
put the following expression
( .='a' and \${Q1_name}<10 ) OR ( .='b' and \${Q1_name}>=10 and
\${Q1_name}<=20 ) OR ( .='c' and \${Q1_name}>20 )
in the constraint column of Q2
Note that in this expression, "." is put for \${Q2_name}.
Hope that helps.
Best,

Â·Â·Â· Le vendredi 10 mars 2017 13:18:51 UTC+1, Tony a Ă©crit : > > Hi everyone, > I am having a problem like this: I want to put a constraint between an > integer input and a choice in multiple choice question. > > Q1. How much do you spend on food everyday? _________ > > Q2. Please select the range ? > > a. Less than 10usd > b. Between 10usd and 20usd > c. More than 20usd > > I want to put a constraint that warn the surveyors in case they input > 50usd and select a or b. Is there anyway to do that. > > Thank you very much. >
1 Like

It works great thank you.

Hi Tony,

as i user of ODK, i am asking one thing about your question and answer of Amal. May i know please which element has been used for the syntax as Amal replied. I used "selected" but it didn't work...

Dev

First posted by Tony

Hello !

I am having a problem like this: I want to put a constraint between an
integer input and a choice in multiple choice question.
q1. How much do you spend on food everyday? _________

q2. Please select the range ?

1. Less than 10usd
2. Between 10usd and 20usd
3. More than 20usd

I want to put a constraint that warn the surveyors in case they input 50usd
and select 1 or 2. Is there anyway to do that.

I just copied that I faced the similar case and I follow as given instruction using the xls syntax â€ś(q2='1' and \${q1}<10 ) or (q2='2' and \${q1}>=10 and q2=2 and \${q1}<=20) or ( q2='3' and \${q1}>20)â€ť BUT I could not get success so could you please help me to make right syntaxâ€¦

Thank you very much.

Dev Maharjan

Hi @debu_odk
I think it should be `(selected(., 'q2a') and /data/q1 < 10) or (selected(., 'q2b') and /data/q1 > 10 and /data/q1 < 20) or (selected(., 'q2c') and /data/q1 > 20)`
look at the xls file and the form:
test.xml (1.4 KB)
test.xlsx (7.6 KB)

Regards,
Grzegorz

1 Like

Dear Grzegorz,

Thank you very much for assisting me on the matter unfortunately it didn't work what i expecting when i tested and tried uploading. I got the results which i have attached...but i am not much aware about xml codes... I hope you can develope new syntax for it.

Regards..
Dev Maharjan

It works well if you use this form in Collect app I don't know why it doesn't work in Enketo preview and I'cant help because I am focused only on ODK Collect. Do you want to use this form in Collect or Enketo?

Regards,
Grzegorz

Dear Grzegorz,

Thank you very much for your kind response. I tried in Kobotoolbox...

Regards

Dev

in that case you should report this fact to Kobotoolbox as I said it's ok if I use the Collect app.

Regards,
Grzegorz