Check out the LimeSurvey source code on GitHub!

disable next button until minimum ranked items is completed.

More
5 years 4 months ago #65448 by bwoo5
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');
});

});

Please Log in to join the conversation.

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

Please Log in to join the conversation.

More
5 years 4 months ago #65468 by bwoo5
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.

Please Log in to join the conversation.

More
4 years 6 months ago #83521 by CatherineA
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?

Please Log in to join the conversation.

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

Please Log in to join the conversation.

More
4 years 6 months ago #83535 by CatherineA
I would like it to be disabled until participants either click on the button or move the slider.

Thanks for your quick reply!
Attachments:

Please Log in to join the conversation.

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

Please Log in to join the conversation.

More
4 years 6 months ago #83539 by CatherineA
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.

Please Log in to join the conversation.

More
4 years 6 months ago - 4 years 6 months ago #83540 by tpartner
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...2516.lss
File Size:37 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last Edit: 4 years 6 months ago by tpartner.

Please Log in to join the conversation.

More
4 years 6 months ago #83541 by CatherineA
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?

Please Log in to join the conversation.

More
4 years 6 months ago - 4 years 6 months ago #83543 by tpartner
Change the script to this:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Initially disable the Next/Submit button
		$('#movesubmitbtn, #movenextbtn').attr('disabled', 'disabled');
 
		// Listener on the slider
		$('.ui-slider').bind('slidechange', function(event, ui) {
			$('#movesubmitbtn, #movenextbtn').attr('disabled', '');
		});
 
		// Listener on the slider
		$('input.radio').click(function(){
			$('#movesubmitbtn, #movenextbtn').attr('disabled', '');
		});
 
	});
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 4 years 6 months ago by tpartner.
The following user(s) said Thank You: CatherineA

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form