- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Hiding multiple choice with comments text box and more
- uxexp
- Topic Author
- Offline
- New Member
Less
More
12 years 4 months ago - 12 years 4 months ago #70804
by uxexp
Hiding multiple choice with comments text box and more was created by uxexp
Hello,
I am using a multiple choice with comments question type. Some of the choices do not require further comments while other do. Can I hide the comments box next to the choices that do not require comments. For exmple:
Q: Choose the websites you have visited in the past:
1. Facebook (no comments)
2. Google (no comments)
3. A work related website [please specify in the comment box]
4. An entertainment website [please specify in the comment box]
Also, is it possible to make the comment piece mandatory for answer choices 3 and 4 (only if selected) in the above example?
Lastly, I would like to capture the first 2 checked labels from the above choices in two separate hidden short text boxes to ask follow-up questions. So for example, if the user chose Google and listed Yahoo Finance for work related website I would like to populate the two short text boxes with "Google" and "Yahoo Finance".
Appreciate your help!
Thanks.
I am using a multiple choice with comments question type. Some of the choices do not require further comments while other do. Can I hide the comments box next to the choices that do not require comments. For exmple:
Q: Choose the websites you have visited in the past:
1. Facebook (no comments)
2. Google (no comments)
3. A work related website [please specify in the comment box]
4. An entertainment website [please specify in the comment box]
Also, is it possible to make the comment piece mandatory for answer choices 3 and 4 (only if selected) in the above example?
Lastly, I would like to capture the first 2 checked labels from the above choices in two separate hidden short text boxes to ask follow-up questions. So for example, if the user chose Google and listed Yahoo Finance for work related website I would like to populate the two short text boxes with "Google" and "Yahoo Finance".
Appreciate your help!
Thanks.
Last edit: 12 years 4 months ago by uxexp.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10110
- Thank you received: 3593
12 years 4 months ago - 12 years 4 months ago #70818
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 Hiding multiple choice with comments text box and more
I assume that the "two separate hidden short text boxes" are in a multiple-text question.
Lets call the multiple-options-with-comments question Q1 and the multiple-text question Q2
If Q1 and Q2 are on the same page, you can do this:
1) Set up your survey to use JavaScript .
2) Add the following script to the source of one of the questions. Replace "11" with the Q1 question ID and "22" with the Q2 question ID .
The script does the following:
- Hides the first two text inputs in Q1
- Makes the visible comments mandatory if their associated box is checked
- Loads the text of the first two checked options in Q1 into the text inputs of Q2 (if the option has a visible comment, that is loaded instead)
Lets call the multiple-options-with-comments question Q1 and the multiple-text question Q2
If Q1 and Q2 are on the same page, you can do this:
1) Set up your survey to use JavaScript .
2) Add the following script to the source of one of the questions. Replace "11" with the Q1 question ID and "22" with the Q2 question ID .
The script does the following:
- Hides the first two text inputs in Q1
- Makes the visible comments mandatory if their associated box is checked
- Loads the text of the first two checked options in Q1 into the text inputs of Q2 (if the option has a visible comment, that is loaded instead)
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var q1ID = 11; var q2ID = 22; var msg = 'Please specify in the comment box.'; // Hide the first 2 text inputs of Q1 $('#question'+q1ID+' li[id^="javatbd"]:eq(0) .comment').hide(); $('#question'+q1ID+' li[id^="javatbd"]:eq(1) .comment').hide(); // Interrupt next/submit function $('#movenextbtn, #movesubmitbtn').click(function(){ // Reset some stuff var failedMandatory = 0; $('#question'+q1ID+' input.text').css({'background':''}); $('#question'+q2ID+' input.text').val(''); // Loop through all check answers in Q1 $('#question'+q1ID+' input.checkbox:checked').each(function(i){ // Define the row var thisRow = $(this).parents('li:eq(0)'); // Check for empty mandatory text inputs if($('input.text:visible', thisRow).length > 0 && $('input.text', thisRow).val() == '') { $('input.text', thisRow).css({'background':'pink'}); failedMandatory = 1; } // Load the multiple-text question if($('input.text:visible', thisRow).length > 0) { $('#question'+q2ID+' input.text:eq('+i+')').val($('input.text', thisRow).val()); } else { $('#question'+q2ID+' input.text:eq('+i+')').val($.trim($(this).parent().text())); } }); // Abort submit if any mandatory text inputs are empty if(failedMandatory == 1) { alert (msg); return false; } else { return true; } }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 12 years 4 months ago by tpartner.
The topic has been locked.
- uxexp
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
12 years 4 months ago #70828
by uxexp
Replied by uxexp on topic Hiding multiple choice with comments text box and more
SIMPLY WONDERFUL!!
On a different note: would recommend a book on JavaScript for beginners?
On a different note: would recommend a book on JavaScript for beginners?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10110
- Thank you received: 3593
12 years 4 months ago #70833
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 Hiding multiple choice with comments text box and more
Hmm...it's been a while...
You'll probably want something on jQuery too - have a look at these:
1) www.peachpit.com/store/product.aspx?isbn=0321772970
2) www.peachpit.com/store/product.aspx?isbn=0321647491
You'll probably want something on jQuery too - have a look at these:
1) www.peachpit.com/store/product.aspx?isbn=0321772970
2) www.peachpit.com/store/product.aspx?isbn=0321647491
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- uxexp
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
12 years 4 months ago #70894
by uxexp
Replied by uxexp on topic Hiding multiple choice with comments text box and more
Thanks much Tony!
The topic has been locked.
- tomdelf
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
12 years 2 months ago #74208
by tomdelf
Replied by tomdelf on topic Hiding multiple choice with comments text box and more
Hi,
this was exactly what i was looking for, but i'm having problems with the second part, ie. if the checkbox is checked, the comment box is mandatory.
It doesn't work for me and i have no idea why I can just simply submit answers without comment boxes being mandatory, i get no alert messages.
Any clues where to start looking?
Cheers,
Tom
this was exactly what i was looking for, but i'm having problems with the second part, ie. if the checkbox is checked, the comment box is mandatory.
It doesn't work for me and i have no idea why I can just simply submit answers without comment boxes being mandatory, i get no alert messages.
Any clues where to start looking?
Cheers,
Tom
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
12 years 2 months ago #74209
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 Hiding multiple choice with comments text box and more
Please post a link to a simple test survey containing the adapted code.
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.
- tomdelf
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
12 years 2 months ago #74242
by tomdelf
Replied by tomdelf on topic Hiding multiple choice with comments text box and more
Sorry, false alarm... seems to work now!
Many thanks in any case for your prompt response!
Tom
Many thanks in any case for your prompt response!
Tom
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
12 years 2 months ago #74247
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 Hiding multiple choice with comments text box and more
You're welcometomdelf wrote: Sorry, false alarm... seems to work now!
Many thanks in any case for your prompt response!
Tom
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.
- benmok
- Offline
- New Member
Less
More
- Posts: 1
- Thank you received: 0
10 years 11 months ago #96163
by benmok
Replied by benmok on topic Hiding multiple choice with comments text box and more
Hi - How do you make it the text box only appear for those that the respondent select in the check box?
Thanks,
Ben
Thanks,
Ben
The topic has been locked.
- AGK925
- Offline
- New Member
Less
More
- Posts: 16
- Thank you received: 3
10 years 2 months ago #105317
by AGK925
Replied by AGK925 on topic Hiding multiple choice with comments text box and more
Hello,
I am new to LimeSurvey and fairly new to Java. I am attempting to use the code above for a survey and I am running into some trouble.
I would like to hide the first three comment boxes and check that the remaining comments are filled in when the corresponding multiple choice is selected. I do not need to pipe in the text responses to another question. Below is the code I am attempting to use to accomplish my tasks.
If I just use the first part that hides the text inputs it works fine. However, when I include everything from "// Interrupt next/submit function" down it does not work, and the text inputs are no longer hidden.
Any help would be greatly appreciated.
Tony
I am new to LimeSurvey and fairly new to Java. I am attempting to use the code above for a survey and I am running into some trouble.
I would like to hide the first three comment boxes and check that the remaining comments are filled in when the corresponding multiple choice is selected. I do not need to pipe in the text responses to another question. Below is the code I am attempting to use to accomplish my tasks.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var q1ID = 68; var msg = 'Please specify in the comment box.'; // Hide the first 3 text inputs of Q1 $('#question'+q1ID+' li[id^="javatbd"]:eq(0) .comment').hide(); $('#question'+q1ID+' li[id^="javatbd"]:eq(1) .comment').hide(); $('#question'+q1ID+' li[id^="javatbd"]:eq(2) .comment').hide(); // Interrupt next/submit function $('#movenextbtn, #movesubmitbtn').click(function(){ // Reset some stuff var failedMandatory = 0; $('#question'+q1ID+' input.text').css({'background':''});; // Loop through all check answers in Q1 $('#question'+q1ID+' input.checkbox:checked').each(function(i){ // Define the row var thisRow = $(this).parents('li:eq(0)'); // Check for empty mandatory text inputs if($('input.text:visible', thisRow).length > 0 && $('input.text', thisRow).val() == '') { $('input.text', thisRow).css({'background':'pink'}); failedMandatory = 1; } }); // Abort submit if any mandatory text inputs are empty if(failedMandatory == 1) { alert (msg); return false; } else { return true; } }); }); </script>
If I just use the first part that hides the text inputs it works fine. However, when I include everything from "// Interrupt next/submit function" down it does not work, and the text inputs are no longer hidden.
Any help would be greatly appreciated.
Tony
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
10 years 2 months ago #105351
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 Hiding multiple choice with comments text box and more
Please post a link to an activated test survey.
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.