Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Set default selected array item to 0

  • teracomp
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
5 years 7 months ago #173278 by teracomp
Set default selected array item to 0 was created 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.
Code:
<script type="text/javascript">
$(document).ready(function(){
  for( var i=1; i<12; i++ ){
   $("#answer111133X316X6454age" + i + "_nbr1 option[value='0']").prop('selected', true);
  }
});
</script>

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

Thanks for looking.

Dave Phillips
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago #173295 by tpartner
Replied by tpartner on topic Set default selected array item to 0
I think you could set the default with an equation question.

Something like:

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

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

Cheers,
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
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose