- Posts: 1
- Thank you received: 0
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
- Topic Author
- Offline
- New Member
Less
More
13 years 4 months ago #54706
by stefann
Is there a way to ask for a month and year in a single question? was created 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?
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
13 years 3 months ago #54712
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on 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.
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.
- aeso
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
12 years 6 months ago #66814
by aeso
Replied by aeso on 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!
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
12 years 6 months ago #66816
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on 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
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
12 years 6 months ago #66820
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Is there a way to ask for a month and year in a single question?
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.
- aeso
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
12 years 6 months ago #66825
by aeso
Replied by aeso on topic Is there a way to ask for a month and year in a single question?
Fantastic, this works perfectly! Wonderful work!
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
12 years 6 months ago #66845
by Mazi
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
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Is there a way to ask for a month and year in a single question?
You're welcome!aeso wrote: Fantastic, this works perfectly! Wonderful work!
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
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- mrli999
- Offline
- Premium Member
Less
More
- Posts: 146
- Thank you received: 2
10 years 3 months ago #103389
by mrli999
Can I still use it in 2.05? I create two date questions, and then put those codes in each question?
Replied by mrli999 on topic Is there a way to ask for a month and year in a single question?
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
10 years 3 months ago #103400
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on 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.
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.
- mrli999
- Offline
- Premium Member
Less
More
- Posts: 146
- Thank you received: 2
10 years 3 months ago #103405
by mrli999
If I use / as the separator characte, are the codes the same?
Replied by mrli999 on 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.
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
10 years 3 months ago #103406
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on 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.
The topic has been locked.
- mrli999
- Offline
- Premium Member
Less
More
- Posts: 146
- Thank you received: 2
10 years 3 months ago #103407
by mrli999
Replied by mrli999 on 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?
The topic has been locked.