Welcome to the LimeSurvey Community Forum

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

Different sufixes in multiple numeric input questions

  • Vinicos
  • Vinicos's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 10 months ago #197121 by Vinicos
Hello,

I want to use different sufixes in a multiple numeric input question.

I have found two syntaxes in previous topics from this forum:

First:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
var thisQuestion = $('#question{QID}');

$('input.text:eq(0)', thisQuestion).after('/day')
$('input.text:eq(1)', thisQuestion).after('/month')
$('input.text:eq(2)', thisQuestion).after('/year')
$('input.text:eq(3)', thisQuestion).after('/decade')
});
</script>

Second:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#question'+{QID}+' li.question-item:eq(0) span.input').append('per minute');
$('#question'+{QID}+' li.question-item:eq(1) span.input').append('per hour');
$('#question'+{QID}+' li.question-item:eq(2) span.input').append('per day');
});
</script>

I have been trying for days to use this syntaxes, but I failed. I might be doing something wrong, as I'm not good at all with javascript language. Can someone please tell me what exatcly I need to change in this syntaxes?

My question code is "ImmigrationTime", the subquestions code are "years" and "months", and the sufixes I want are "anos e" and "meses".

Thanks.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago #197128 by holch
Just like in the other post: you might be using code for older versions. The template system has changed quite a bit with each of the last major releases, so workarounds for older versions generally don't work with newer versions anymore.

So please post which version you are using.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
  • Vinicos
  • Vinicos's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 10 months ago #197136 by Vinicos
Thanks, holch
As I mentioned in the other post, I'm using the version 3.17.7
The topic has been locked.
  • Vinicos
  • Vinicos's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 10 months ago #197137 by Vinicos
3.17.7+190627 ***
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago #197140 by Joffm
Hi,
if you ask for a date, your idea is the worst of all (in my opinion).
Why?
You have to validate both fields of the multiple numeric input, to avoid "1673" and "24" as month.

For a date you should either use a date question.


or you may use an array(numbers)
Here the dropdowns are restricted to your allowed values


or you may use a different datepicker (which I found, but won't recommend)



Here an example of all three options.

File Attachment:

File Name: limesurvey...9514.lss
File Size:28 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Vinicos
  • Vinicos's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 10 months ago #197143 by Vinicos
Thanks, Joffm,

But I'm actually asking the amount of time that the participant has spent living abroad:

"How long have you been living abroad?"

The answer would be two numeric inputs:

___ years and
___ months

I have already put validation subquestion equations for years (less than age) and also months (less than 12). I only need now the information I asked concerning how to use different sufixes.

Later on, I will make similar questions regarding the amount of time that the participant is in a relationship, etc.

A date question would also fit, but I prefer to ask for the amount of time, just like in other similar surveys I have myself participated.

Vini
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago #197145 by tpartner
Try this:

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).on('ready pjax:complete',function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    $('input:text:eq(0)', thisQuestion).after('per minute');
    $('input:text:eq(1)', thisQuestion).after('per hour');
    $('input:text:eq(2)', thisQuestion).after('per day');
 
    $('input:text', thisQuestion).css({
      'display': 'inline-block',
      'margin-right': '0.5em'
    });
  });  
</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.
  • Vinicos
  • Vinicos's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 10 months ago #197149 by Vinicos
I tried, but it didn't work.
I'm not sure if I did it right:

<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:complete',function() {

// Identify this question
var thisQuestion = $('#question{ImmigrationTime}');

$('input:text:eq(years)', thisQuestion).after('anos e');
$('input:text:eq(months)', thisQuestion).after('meses');

$('input:text', thisQuestion).css({
'display': 'inline-block',
'margin-right': '0.5em'
});
});
</script>

Question code: ImmigrationTime
subquestions code: "years" and "months"
sufixes: "anos e" and "meses"
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago #197153 by tpartner
Do not change the ExpressionScript tag or the selector indexes
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:complete',function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    $('input:text:eq(0)', thisQuestion).after('anos e');
    $('input:text:eq(1)', thisQuestion).after('meses');
 
    $('input:text', thisQuestion).css({
    'display': 'inline-block',
    'margin-right': '0.5em'
    });
  });
</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: holch
The topic has been locked.
  • Vinicos
  • Vinicos's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 10 months ago #197155 by Vinicos
It worked well. Thanks very much!
But I have now a new problem. As you may see on the attached pic, the sufixes are ok, but they are under the box. Also, they anserboxes are drawn to the right. Is there a way I could have the sufixes beside the boxes and also the boxes drawn to the left?

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago #197156 by tpartner
Please refer to the manual - Label column width - www.limesurvey.org/manual/Question_type_...abel_column_width.29

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Vinicos
  • Vinicos's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
4 years 10 months ago #197158 by Vinicos
Thanks, tpartner!
It's just perfect now.
The topic has been locked.
Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose