Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

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

Is there a way to ask for a month and year in a single question? 3 years 3 months ago #54706

  • stefann
  • stefann's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
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 administrator has disabled public write access.

Re: Is there a way to ask for a month and year in a single question? 3 years 3 months ago #54712

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
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.
<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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: aeso

Re: Is there a way to ask for a month and year in a single question? 2 years 6 months ago #66814

  • aeso
  • aeso's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
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 administrator has disabled public write access.

Re: Is there a way to ask for a month and year in a single question? 2 years 6 months ago #66816

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5279
  • Thank you received: 289
  • Karma: 246
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
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Is there a way to ask for a month and year in a single question? 2 years 6 months ago #66820

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
This should do the trick:
<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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: aeso

Re: Is there a way to ask for a month and year in a single question? 2 years 6 months ago #66825

  • aeso
  • aeso's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
Fantastic, this works perfectly! Wonderful work!
The administrator has disabled public write access.

Re: Is there a way to ask for a month and year in a single question? 2 years 6 months ago #66845

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5279
  • Thank you received: 289
  • Karma: 246
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
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Is there a way to ask for a month and year in a single question? 3 months 1 week ago #103389

  • mrli999
  • mrli999's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 84
  • Thank you received: 1
  • Karma: 0
tpartner wrote:
This should do the trick:
<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 administrator has disabled public write access.

Re: Is there a way to ask for a month and year in a single question? 3 months 1 week ago #103400

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Here is an updated version for 2.05. Add this script to the source of every date question you want affected.
<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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Is there a way to ask for a month and year in a single question? 3 months 1 week ago #103405

  • mrli999
  • mrli999's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 84
  • Thank you received: 1
  • Karma: 0
tpartner wrote:
Here is an updated version for 2.05. Add this script to the source of every date question you want affected.
<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 administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.151 seconds
Donation Image