Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Additional Checkbox below textfield

Re: Additional Checkbox below textfield 1 year 4 months ago #96569

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4271
  • Thank you received: 806
  • Karma: 369
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_survey_4768832.lss
File Size: 15 KB
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 1 year 4 months ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: misterdot

Re: Additional Checkbox below textfield 1 year 4 months ago #96575

  • misterdot
  • misterdot's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Thank you received: 1
  • Karma: 0
Works beautifully - thanks so much!
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.105 seconds
Donation Image