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

TOPIC: disable next button until minimum ranked items is completed.

disable next button until minimum ranked items is completed. 2 years 10 months ago #65448

  • bwoo5
  • bwoo5's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 80
  • Thank you received: 4
  • Karma: 0
I have a ranking question that has a minimum of 3 items to be ranked. it is the only question on the page. how can i disable the next button until they have ranked the correct number of items? i saw the code below for disabling the submit button in a radio button question, but i need code to disable the next button until the minimum number of ranked items is completed.

<script type="text/javascript" charset="utf-8">

$(document).ready(function() {

// Initially disable the Next/Submit button
$('input[type="submit"]').attr('disabled', 'disabled');

// Listeners on Yes/No radios to toggle the Next/Submit button
$('input.radio[value="Y"]').click(function(){
$('input[type="submit"]').attr('disabled', '');
});
$('input.radio[value="N"]').click(function(){
$('input[type="submit"]').attr('disabled', 'disabled');
});

});
The administrator has disabled public write access.

Re: disable next button until minimum ranked items is completed. 2 years 10 months ago #65467

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4058
  • Thank you received: 742
  • Karma: 341
Try this:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		var minRanked = 3;
 
		// Initially disable the Next/Submit button
		$('input[type="submit"]').attr('disabled', 'disabled');
 
		// Listeners on ranking elements
		$('.ranking td.label, .ranking td.output img').click(function(){
 
			var count = 0;
 
			// Count the ranked items 
			$('.ranking td.output input.text').each(function(i){
				if($(this).val()) {
					count++;
				}
			});
 
			// Toggle the Next/Submit button
			if(count >= minRanked) {
				$('input[type="submit"]').attr('disabled', '');
			}
			else {
				$('input[type="submit"]').attr('disabled', 'disabled');
			}
		});
 
	});
 
</script>
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.
The administrator has disabled public write access.

Re: disable next button until minimum ranked items is completed. 2 years 10 months ago #65468

  • bwoo5
  • bwoo5's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 80
  • Thank you received: 4
  • Karma: 0
Thanks tpartner! you have always helped everyone out so much. I did the comfort update and it solved the issues I was having with the ranking questions. I just need to figure out how to update the language file. I installed poedit and found the comment I need to edit, just not sure how to do it as of yet.
The administrator has disabled public write access.

Re: disable next button until minimum ranked items is completed. 2 years 1 week ago #83521

  • CatherineA
  • CatherineA's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 21
  • Karma: 0
Hi!
I am facing the same problem: I have two questions presented side by side, and I want to force participants to respond to one of the two questions (one is a slider, the other is a radio button).
How can I change the code so that once the respondant has clicked either on the slider or on the radio button, the "next" button appears?
The administrator has disabled public write access.

Re: disable next button until minimum ranked items is completed. 2 years 1 week ago #83534

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4058
  • Thank you received: 742
  • Karma: 341
Catherine, do you want the "Next" button to be hidden or just disabled until the requirements are met?

Can you attach a small sample survey with only that group in it?
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.
The administrator has disabled public write access.

Re: disable next button until minimum ranked items is completed. 2 years 1 week ago #83535

  • CatherineA
  • CatherineA's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 21
  • Karma: 0
I would like it to be disabled until participants either click on the button or move the slider.

Thanks for your quick reply!
Attachments:
The administrator has disabled public write access.

Re: disable next button until minimum ranked items is completed. 2 years 1 week ago #83538

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4058
  • Thank you received: 742
  • Karma: 341
Hmm...you have given the slider an initial value so it's impossible to tell if a respondent has previously moved the slider.

Are your respondents allowed to go backwards in the survey?

And what if the respondent likes the initial value of the slider so doesn't want to change it?
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.
The administrator has disabled public write access.

Re: disable next button until minimum ranked items is completed. 2 years 1 week ago #83539

  • CatherineA
  • CatherineA's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 21
  • Karma: 0
Ouh! I appologize, in the last version, I erased the initial value. There is no value in the slider until the participant has touched it.

My respondants aren't allowed to go backwards in the survey.
The administrator has disabled public write access.

Re: disable next button until minimum ranked items is completed. 2 years 1 week ago #83540

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4058
  • Thank you received: 742
  • Karma: 341
In that case, add the following script to the source of one of the questions in that group (in the attached survey, I have added it to the source of the slider question):
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Initially disable the Next/Submit button if the slider has never been moved and the radio is unchecked
		if($('.multinum-slider input[id^="answer"]').val() == '' && $('input.radio:checked').length == 0) {
			$('#movesubmitbtn, #movenextbtn').attr('disabled', 'disabled');
		}
 
		var sliderChanged = '';
 
		// Listener on the slider
		$('.ui-slider').bind('slidechange', function(event, ui) {
			sliderChanged = 1;
			if($('input.radio:checked').length > 0) {
				$('#movesubmitbtn, #movenextbtn').attr('disabled', '');
			}
		});
 
		// Listener on the radio
		$('input.radio').click(function(){
			if(sliderChanged > 0) {
				$('#movesubmitbtn, #movenextbtn').attr('disabled', '');
			}
		});
 
	});
 
</script>


File Attachment:

File Name: limesurvey_survey_12516.lss
File Size: 37 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: 2 years 1 week ago by tpartner.
The administrator has disabled public write access.

Re: disable next button until minimum ranked items is completed. 2 years 1 week ago #83541

  • CatherineA
  • CatherineA's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 21
  • Karma: 0
Thank you this is amazing!
Although, I would like the button "next" to appear if the participant either moves the slide, or selects the button. When I use your script, I have to move the slider AND to click on the button.. Is it possible to put in the scipt that only one "answer" is needed?
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.157 seconds
Donation Image