Welcome to the LimeSurvey Community Forum

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

Additional Checkbox below textfield

  • Dolgsthrasir
  • Dolgsthrasir's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 9 months ago - 12 years 9 months ago #61844 by Dolgsthrasir
Additional Checkbox below textfield was created by Dolgsthrasir
Hello,

I am trying to setup a survey where some questions consist of three radio buttons, an additional textfield for comments and a checkbox below this textfield. With the additional checkbox the participants can mark that the comment in the textbox is of high importance for them.

To demonstrate what I mean, a short (photoshoped) example.



So my question is: is there a possibility to add a checkbox like this? Beyond that, is there a way to change the "Please enter your comment here" to something else (varying from question to question).

Appreciate any help

Greetings
Attachments:
Last edit: 12 years 9 months ago by Dolgsthrasir. Reason: typo
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 9 months ago #61866 by tpartner
Replied by tpartner on topic Additional Checkbox below textfield
To get the checkbox you will need to use another question. Add a multiple choice question with no question text (or hide the question text with CSS) and only one sub-question.

To dynamically modify the label text:

1) Set up your survey to use JavaScript .

2) Add the following script to the source of the question. Replace "QQ" with the question ID .
Code:
<script type="text/javascript" charset="utf-8">
 
  $('#questionQQ p.comment label').text('Some new label text...');
 
</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.
  • Dolgsthrasir
  • Dolgsthrasir's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 9 months ago #61869 by Dolgsthrasir
Replied by Dolgsthrasir on topic Additional Checkbox below textfield
It works, thank you very much!
The topic has been locked.
More
11 years 9 months ago #82660 by FLF
Replied by FLF on topic Aw: Additional Checkbox below textfield
Hello,
I have the same problem like Dolgsthrasir. I want to change the text "Please enter your comment here"
So I used the javascript like described, but it doesn't work.
Is it possible that the the limesurvey version Version changed and that's the reason.

I use version 1.92+
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 9 months ago #82665 by tpartner
Replied by tpartner on topic Additional Checkbox below textfield
No, that selector should still work.

Can you activate a sample survey with your code in it?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
11 years 9 months ago #82723 by FLF
Replied by FLF on topic Additional Checkbox below textfield
Thank you for your answer.
Now it works. For some reason in the HTML source code the javascript code was above the code for the question.
So I included the javasript code into the question-group endgroup.pstpl and now it works. I know that the code is now in every question-group, but I think that there should be no problem.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 9 months ago #82729 by tpartner
Replied by tpartner on topic Additional Checkbox below textfield
Oh, wait, I see the problem. The script is being fired before the page is loaded.

This should work in the question source:
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function(){
 
    $('#questionQQ p.comment label').text('Some new label text...');
  });
 
</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.
More
11 years 9 months ago #82739 by FLF
Replied by FLF on topic Additional Checkbox below textfield
:) thank you!!
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
11 years 9 months ago #82853 by Mazi
Replied by Mazi on topic Additional Checkbox below textfield

FLF wrote: :) thank you!!

You're welcome :-)

If our hints have been helpful and you enjoy limesurvey please consider a donation to give Limesurvey a future .
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.
More
10 years 10 months ago #96546 by misterdot
Replied by misterdot on topic Additional Checkbox below textfield
I'm having trouble getting this to work. I'm using Version 2.00+ Build 130305 and javascript is enabled (using it elsewhere). I've attached a screen shot of what I'd like it to be and a sample (not working) survey. Can't figure out what I'm doing wrong.
Thanks!
Matt
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 9 months ago - 10 years 9 months ago #96569 by tpartner
Replied by tpartner on topic Additional Checkbox below textfield
Here is an updated script that hides the check-box question and moves the check-box and label into the numeric question.

This script also makes the numeric input and check-box exclusive.

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function(){
 
    // Identify the questions
    var q1ID = '{QID}';
    var q1 = $('#question'+q1ID+'');
    var q2 = $(q1).nextAll('.multiple-opt:eq(0)'); 
    var q2ID = $(q2).attr('id').split('question')[1];
 
    // Hide Q2
    $(q2).css({
      'position': 'absolute',
      'left': '-9999em'
    });
 
    // Move the checkbox and label to Q1
    $('.answer-item', q1).after($('.checkbox-list', q2));
 
    // Some cleanup styles
    $('.checkbox-list', q1).css({
      'margin-left': $('.answer-item', q1).css('margin-left'),
      'list-style': 'none'
    })
 
    // Listener on the numeric input
    $('input[type="text"]', q1).keyup(function(){
      if($(this).val() != '') {
        $('input.checkbox', q1).attr('checked', false);
      }
    });
 
    // Listener on the checkbox
    $('input.checkbox', q1).change(function(){
      if($(this).attr('checked') == true) {
        $('input[type="text"]', q1).val('');
      }
    });
  });
</script>


Here is the survey back with the updated script in the source of the numeric question:

File Attachment:

File Name: limesurvey...8832.lss
File Size:15 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 9 months ago by tpartner.
The following user(s) said Thank You: misterdot
The topic has been locked.
More
10 years 9 months ago #96575 by misterdot
Replied by misterdot on topic Additional Checkbox below textfield
Works beautifully - thanks so much!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose