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

More
6 years 9 months ago #54706 by stefann
stefann created the 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, 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?

Please Log in to join the conversation.

More
6 years 9 months ago #54712 by tpartner
tpartner replied the topic: Is there a way to ask for a month and year in a single question?
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.
The following user(s) said Thank You: aeso

Please Log in to join the conversation.

More
6 years 1 week ago #66814 by aeso
aeso replied the topic: Is there a way to ask for a month and year in a single question?
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!

Please Log in to join the conversation.

More
6 years 1 week ago #66816 by Mazi
Mazi replied the topic: Is there a way to ask for a month and year in a single question?
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)survey-consulting.com'"

Please Log in to join the conversation.

More
6 years 1 week ago #66820 by tpartner
tpartner replied the topic: Is there a way to ask for a month and year in a single question?
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.
The following user(s) said Thank You: aeso

Please Log in to join the conversation.

More
6 years 1 week ago #66825 by aeso
aeso replied the topic: Is there a way to ask for a month and year in a single question?
Fantastic, this works perfectly! Wonderful work!

Please Log in to join the conversation.

More
6 years 1 week ago #66845 by Mazi
Mazi replied the topic: Is there a way to ask for a month and year in a single question?

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)survey-consulting.com'"

Please Log in to join the conversation.

More
3 years 9 months ago #103389 by mrli999
mrli999 replied the topic: Is there a way to ask for a month and year in a single question?

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?

Please Log in to join the conversation.

More
3 years 9 months ago #103400 by tpartner
tpartner replied the topic: Is there a way to ask for a month and year in a single question?
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.

Please Log in to join the conversation.

More
3 years 9 months ago #103405 by mrli999
mrli999 replied the topic: Is there a way to ask for a month and year in a single question?

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?

Please Log in to join the conversation.

More
3 years 9 months ago #103406 by tpartner
tpartner replied the topic: Is there a way to ask for a month and year in a single question?
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.

Please Log in to join the conversation.

More
3 years 9 months ago #103407 by mrli999
mrli999 replied the topic: Is there a way to ask for a month and year in a single question?
Then if the format is yyyy/mm/dd, will it also work?

Please Log in to join the conversation.

More
3 years 9 months ago #103408 by tpartner
tpartner replied the topic: Is there a way to ask for a month and year in a single question?
Please test

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
3 years 9 months ago #103409 by mrli999
mrli999 replied the topic: Is there a way to ask for a month and year in a single question?

tpartner wrote: Please test


It doesn't work. I remove the first/. Maybe you want to remove the last / in that case.

Please Log in to join the conversation.

More
3 years 9 months ago #103410 by tpartner
tpartner replied the topic: Is there a way to ask for a month and year in a single question?
Change this:
$('span.date-separator:eq(0)', thisQuestion).hide();


To this:
$('span.date-separator:eq(1)', thisQuestion).hide();

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: mrli999

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now