# Logic with 2 questions

Dear All,

I have 2 questions as below:

Q1. (select question) have 5 answers.
Q: How many children do you have?
A: 1. 1 child  | 2. 2 children | 3. 3 children | 4. 4 children | 5. More than 4 children

Q2. (Grid question as Numberic type)
Q: How old is your children?
A: - If Q1=1 we show only 1 colum to ask first child's age.
- if Q1=2 we show only 2 colums to ask first and second child's age. And second child must be bigger than first child.
- if Q1=3 we show only 3 colums to ask first, second and third child's age. And second child must be bigger than first child. And third child must be bigger than second child.
- if Q1=4 we show 4 colums to ask first, second, third and forth child's age. And second child must be bigger than first child. And third child must be bigger than second child. And forth child must be bigger than third child.

How could i do that? Is it possible?
asked Jan 16, 2017

+1 vote
Hi Saroeun,

There are two tasks in your query.

1. To show only respective columns.

You can create a constructed list "forQ2col"

2. To ensure that first child's age should be less than second second child

You can program a custom javascript here:

var a1=SSI_GetValue("Q2_r1_c1");
var a2=SSI_GetValue("Q2_r1_c2");
var a3=SSI_GetValue("Q2_r1_c3");
var a4=SSI_GetValue("Q2_r1_c4");

var Q1resp=[% Q1 %];

if((Q1resp==5 || Q1resp==4)  && (a4<a3 || a3<a2 || a2<a1))
{
var strErrorMessage="Error";
}
if(Q1resp==3 && (a3<a2 || a2<a1))
{
var strErrorMessage="Error";
}
if(Q1resp==2 && a2<a1)
{
var strErrorMessage="Error";
}

------------------------------------------------------------

Regards,
Saurabh
answered Jan 16, 2017 by Gold (30,135 points)
edited Jan 17, 2017