- Posts: 16
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Adding a textbox in a subquestion (Array)
- jyu183
- Topic Author
- Offline
- New Member
Less
More
2 years 1 month ago #226620
by jyu183
Adding a textbox in a subquestion (Array) was created by jyu183
Please help us help you and fill where relevant:
Your LimeSurvey version: 3.27.26
Own server or LimeSurvey hosting:
Survey theme/template:
==================
Hi all,
Would it be possible to add a textbox in a subquestion? Last subquestion is "Other (please write):", so that respondents can write their own answers.
I would need to do this for both Array and Array (Numbers). I tried the script from array ----add a text box in one subquestion - LimeSurvey forums but for some reason it doesn't seem to work for me unfortunately. Perhaps another way of facilitating this?
Your advice would be much appreciated.
Your LimeSurvey version: 3.27.26
Own server or LimeSurvey hosting:
Survey theme/template:
==================
Hi all,
Would it be possible to add a textbox in a subquestion? Last subquestion is "Other (please write):", so that respondents can write their own answers.
I would need to do this for both Array and Array (Numbers). I tried the script from array ----add a text box in one subquestion - LimeSurvey forums but for some reason it doesn't seem to work for me unfortunately. Perhaps another way of facilitating this?
Your advice would be much appreciated.
Please Log in to join the conversation.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12940
- Thank you received: 3979
2 years 1 month ago #226623
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Adding a textbox in a subquestion (Array)
What do you expect us to answer?
You read that the thread starter of your linked thread with nearly the same version was successful.
So, obviously you missed something.
But this we can only see if you provide a lss export.
Joffm
You read that the thread starter of your linked thread with nearly the same version was successful.
So, obviously you missed something.
But this we can only see if you provide a lss export.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Please Log in to join the conversation.
- jyu183
- Topic Author
- Offline
- New Member
Less
More
- Posts: 16
- Thank you received: 0
2 years 1 month ago #226625
by jyu183
Replied by jyu183 on topic Adding a textbox in a subquestion (Array)
Thanks Joffm; you are right, apologies. I have attached my .lss file here.
Attachments:
Please Log in to join the conversation.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12940
- Thank you received: 3979
2 years 1 month ago #226629
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Adding a textbox in a subquestion (Array)
Hi,
use this script.
It works in "normal arrays and in array(text), array(number)
But this works
And for array(numbers)?
Joffm
use this script.
It works in "normal arrays and in array(text), array(number)
But this works
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify the questions var thisQuestion = $('#question'+{QID}+''); var nextQuestion1 = $(thisQuestion).nextAll('.text-short:eq(0)'); var nextQuestions = $(nextQuestion1); var nextLength = nextQuestions.length; var sqLength = ('tr.answers-list', thisQuestion).length; // Hide the short-text questions $(nextQuestions).hide(); // Move the hidden text inputs into the array for (i = 0; i < nextLength; i++) { var workingIndex = (sqLength - 1) - (nextLength - i); var nextQ = nextQuestions[i]; $('th.answertext:eq('+workingIndex+')', thisQuestion).append($('input[type="text"]', nextQ)).closest('tr').addClass('otherRow'); } // Some styling... $('input[type="text"]', thisQuestion).css({ 'width': '100%' }); }); </script>
And for array(numbers)?
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: jyu183
Please Log in to join the conversation.
- jyu183
- Topic Author
- Offline
- New Member
Less
More
- Posts: 16
- Thank you received: 0
2 years 4 weeks ago #226685
by jyu183
Replied by jyu183 on topic Adding a textbox in a subquestion (Array)
Thank you so much, this works perfectly!
Please Log in to join the conversation.
- Polpolpol
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
1 year 3 months ago - 1 year 3 months ago #239399
by Polpolpol
Replied by Polpolpol on topic Adding a textbox in a subquestion (Array)
Hello, @Joffm
I am a new user and I have tried add a textbox in a subquestion (Array) following your steps. I got it, but only run if I have my survey set up in format "section by section"
But I need launch the survey in the "question by question" mode
With this configuration it seems that the script not run and the two questions are presented in separate form. I attaching a .lss if you can see it. Thank you.
I am a new user and I have tried add a textbox in a subquestion (Array) following your steps. I got it, but only run if I have my survey set up in format "section by section"
But I need launch the survey in the "question by question" mode
With this configuration it seems that the script not run and the two questions are presented in separate form. I attaching a .lss if you can see it. Thank you.
Last edit: 1 year 3 months ago by Polpolpol.
Please Log in to join the conversation.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12940
- Thank you received: 3979
1 year 3 months ago #239400
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Adding a textbox in a subquestion (Array)
Of course it works only in "group by group" mode.
It is obvious, if you have a look to the code.
You see that there are two questions where the second question is merged into the first by javascript.
javascript works in the browser. Therefore it can only handle things that are available in the browser.
If you display "question by question" the second question is not loaded yet.
And the consequence is. You see two separate questions.
Therefore we often recommend to set the survey to "group by group" mode, but with only one question per group.
Now it looks like "question by question" but you still have the option
to display two or more questions on one page
to use some javascript workarounds which need this setting.
Joffm
If you insist on a "question by question" mode you can't use this.
You have to think about a different design of this question.
E.g. a question of type "short text" that is displayed if the respondent selects the subquestion "Other" with a different answer option than "not applicable", or something like that.
It is obvious, if you have a look to the code.
You see that there are two questions where the second question is merged into the first by javascript.
javascript works in the browser. Therefore it can only handle things that are available in the browser.
If you display "question by question" the second question is not loaded yet.
And the consequence is. You see two separate questions.
Therefore we often recommend to set the survey to "group by group" mode, but with only one question per group.
Now it looks like "question by question" but you still have the option
to display two or more questions on one page
to use some javascript workarounds which need this setting.
Joffm
If you insist on a "question by question" mode you can't use this.
You have to think about a different design of this question.
E.g. a question of type "short text" that is displayed if the respondent selects the subquestion "Other" with a different answer option than "not applicable", or something like that.
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Please Log in to join the conversation.
- Polpolpol
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
1 year 3 months ago #239404
by Polpolpol
Replied by Polpolpol on topic Adding a textbox in a subquestion (Array)
I understand, Joffm.
As you suggest, I will set the survey to "group by group" mode, but with only one question per group. I have been making some tests and it doesn't matter for the responses that the questions are organized in one question per group. I see that the concept "group" doesn't have any impact in the responses.
Thanks again!
As you suggest, I will set the survey to "group by group" mode, but with only one question per group. I have been making some tests and it doesn't matter for the responses that the questions are organized in one question per group. I see that the concept "group" doesn't have any impact in the responses.
Thanks again!
Please Log in to join the conversation.