Set default selected array item to 0

7 months 3 weeks ago #173278 by teracomp
I have an Array(Numbers) question type that asks the respondent to identify the number of people in their household for each age range listed. There are 11 age ranges in the y-axis. The x-axis lists 0..5 in a dropdown list to choose from.

I need this question to be mandatory, but obviously, not every age range is in every household. As a result, I needed to set the default value for each y-axis item to 0 and select the drop down. Then the respondent can set the appropriate values where needed.

Here's the code I added to set this default.
<script type="text/javascript">
  for( var i=1; i<12; i++ ){
   $("#answer111133X316X6454age" + i + "_nbr1 option[value='0']").prop('selected', true);

Is this the right approach to solving this? Or did I miss something in the question setup?

Thanks for looking.

Dave Phillips

Please Log in or Create an account to join the conversation.

7 months 3 weeks ago #173295 by tpartner
I think you could set the default with an equation question.

Something like:

{Q1_age1_nbr1 = if(is_empty(Q1_age1_nbr1), 0, Q1_age1_nbr1)}

(I am working from my phone today so can't test)

Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: DenisChenu

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!