Welcome to the LimeSurvey Community Forum

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

Is there a way to ask for a month and year in a single question?

  • stefann
  • stefann's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
13 years 11 months ago #54706 by stefann
Is there a way to ask for a month and year in a single question, without requiring the user to specify a date?

I'm after some general questions like when did you start using these services, for which a specific date is unreasonable and not incredibly useful, but a month and year provides useful data.

Is this possible to achieve this, preferably with a date field?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
13 years 10 months ago #54712 by tpartner
You could use a little JavaScript to hide the day dropdown of a date question and auto-populate it with the 1st day. This way your respondents would only see the month and year dropdowns and your data would show the first day of each month selected.

Create your date question using dropdowns.

Set up your survey to use JavaScript and place the following script in the source of the date question.
Code:
<script type="text/javascript" charset="utf-8">
 
    $(document).ready(function() {
 
        $('.date .day ').hide();
        $('.date .day option:eq(1)').attr('selected', 'selected');
 
    });
 
</script>

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: aeso
The topic has been locked.
More
13 years 1 month ago #66814 by aeso
This solution works perfectly for a single date. Is there an easy way to make it work for multiple date entries on the same page? They all become hidden but only the first one submits properly. Thanks!
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
13 years 1 month ago #66816 by Mazi
How about using the dual scale question type with dropdown layout and then have scale 1 for months and scale 2 for years: docs.limesurvey.org/Question+type+-+Arra...tions+for+LimeSurvey

Best regards/Beste Grüße,
Dr. Marcel Minke
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
13 years 1 month ago #66820 by tpartner
This should do the trick:
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    $('.date .day').hide();
 
    $('.date .day').each(function(){
      $('option:eq(1)', this).attr('selected', 'selected');
    });
  });
 
</script>

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: aeso
The topic has been locked.
More
13 years 1 month ago #66825 by aeso
Fantastic, this works perfectly! Wonderful work!
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
13 years 1 month ago #66845 by Mazi

aeso wrote: Fantastic, this works perfectly! Wonderful work!

You're welcome!

If our hints have been helpful and you enjoy limesurvey please consider a donation to the team .
We do all this in our free time and you don't have to pay a penny for this software.

Without your help we can't keep this project alive.

Best regards/Beste Grüße,
Dr. Marcel Minke
The topic has been locked.
More
10 years 10 months ago #103389 by mrli999

tpartner wrote: This should do the trick:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    $('.date .day').hide();
 
    $('.date .day').each(function(){
      $('option:eq(1)', this).attr('selected', 'selected');
    });
  });
 
</script>



Can I still use it in 2.05? I create two date questions, and then put those codes in each question?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 10 months ago #103400 by tpartner
Here is an updated version for 2.05. Add this script to the source of every date question you want affected.
Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {
 
    // Identify this question
    var qID = {QID};
    var thisQuestion = $('#question'+qID);
 
    // Hide the day dropdown
    $('select.day', thisQuestion).hide();
 
    // Set the day to 1
    $('select.day option:eq(1)', thisQuestion).attr('selected', 'selected');
 
    // Hide the first separator "-" character
    $('.answer-item', thisQuestion).contents().not('label, select, input, :empty').wrap('<span class="date-separator" />');
    $('span.date-separator:eq(0)', thisQuestion).hide();
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
10 years 10 months ago #103405 by mrli999

tpartner wrote: Here is an updated version for 2.05. Add this script to the source of every date question you want affected.

Code:
<script type="text/javascript" charset="utf-8">  
 
  $(document).ready(function() {
 
    // Identify this question
    var qID = {QID};
    var thisQuestion = $('#question'+qID);
 
    // Hide the day dropdown
    $('select.day', thisQuestion).hide();
 
    // Set the day to 1
    $('select.day option:eq(1)', thisQuestion).attr('selected', 'selected');
 
    // Hide the first separator "-" character
    $('.answer-item', thisQuestion).contents().not('label, select, input, :empty').wrap('<span class="date-separator" />');
    $('span.date-separator:eq(0)', thisQuestion).hide();
  });
</script>


If I use / as the separator characte, are the codes the same?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 10 months ago #103406 by tpartner
Yeah, should be. The script just wraps text elements (not labels, dropdowns, etc) in span elements and hides the first one.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
10 years 10 months ago #103407 by mrli999
Then if the format is yyyy/mm/dd, will it also work?
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose