Additional Checkbox below textfield

More
5 years 9 months ago - 5 years 9 months ago #61844 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: 5 years 9 months ago by Dolgsthrasir. Reason: typo

Please Log in to join the conversation.

More
5 years 9 months ago #61866 by tpartner
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 .
<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.

Please Log in to join the conversation.

More
5 years 9 months ago #61869 by Dolgsthrasir
It works, thank you very much!

Please Log in to join the conversation.

More
4 years 9 months ago #82660 by FLF
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+

Please Log in to join the conversation.

More
4 years 9 months ago #82665 by tpartner
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.

Please Log in to join the conversation.

More
4 years 9 months ago #82723 by FLF
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.

Please Log in to join the conversation.

More
4 years 9 months ago #82729 by tpartner
Oh, wait, I see the problem. The script is being fired before the page is loaded.

This should work in the question source:
<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.

Please Log in to join the conversation.

More
4 years 9 months ago #82739 by FLF
:) thank you!!

Please Log in to join the conversation.

More
4 years 8 months ago #82853 by Mazi

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
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
3 years 9 months ago #96546 by misterdot
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
Attachments:

Please Log in to join the conversation.

More
3 years 9 months ago - 3 years 9 months ago #96569 by tpartner
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.

<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.
Attachments:
Last Edit: 3 years 9 months ago by tpartner.
The following user(s) said Thank You: misterdot

Please Log in to join the conversation.

More
3 years 9 months ago #96575 by misterdot
Works beautifully - thanks so much!

Please Log in to join the conversation.