How can I stop the page reloading if mandatory question not answered?

More
4 years 8 months ago #89552 by Melarish
Melarish created the topic: How can I stop the page reloading if mandatory question not answered?
Currently, if the user clicks "next", it reloads the page (and replays the musical stimulus which they are supposed to hear only once). Can I stop it doing that?

I found something in the manual but I'm not sure if this is it. If yes, do I have to put it on every page or just the template for questionpage?
// Interrupt the submit function and validate mandatory questions
			// NOTE: Comment this section out if questions are not mandatory
			$('form#limesurvey').submit(function(){	
				// Override the built-in "disable navigation buttons" feature
				$('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', '');
 
				// Loop through all "shown" questions and check for answer
				var answered = 0;
				$.each(shownQuestions, function(i, val){
					if ( $( 'div#' + val + ' input.radio:checked' ).length == 0 ) {
						$( 'div#' + val + '' ).css('color', 'red');
						answered = 1;
					}	
					else {
						$( 'div#' + val + '' ).css('color', '');
					}
				});
				if ( answered == 1 ) {
					alert ( mandatoryMsg );
					return false;
				}	
				else {
					return true;
				}
			});

Please Log in to join the conversation.

More
4 years 8 months ago #89597 by jelo
jelo replied the topic: Aw: How can I stop the page reloading if mandatory question not answered?
Since they only should hear the sound stimulus once, why don't you put the sound stimulus on a simple page without any question and ask the mandatory question on the next page?

Please Log in to join the conversation.

More
4 years 8 months ago #89635 by tpartner
tpartner replied the topic: How can I stop the page reloading if mandatory question not answered?
That code snippet seems to be incomplete.

What are the mandatory question types and how many are there?

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 8 months ago #89646 by Melarish
Melarish replied the topic: Aw: How can I stop the page reloading if mandatory question not answered?
jelo, that would be wayyyyyyy too much clicking because the whole survey consists of musical stimuli.

tpartner, the question type is List (radio) with 5 options. It's one question per question group. The code is from docs.limesurvey.org/Workarounds%3A+Surve...tions+for+LimeSurvey

Please Log in to join the conversation.

More
4 years 8 months ago - 4 years 8 months ago #89652 by tpartner
tpartner replied the topic: Aw: How can I stop the page reloading if mandatory question not answered?

...the question type is List (radio) with 5 options. It's one question per question group.

Okay, how about hiding the "Next" button until a radio has been clicked? (I am assuming that respondents are not allowed to go backwards in the survey)

1) Set up your survey to use JavaScript .

2) Add the following script to the source of the radio question.

The script hides the "Next" button until a radio has been clicked.
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		// Hide the next button
		$('#movenextbtn').hide();
 
		// Show the next button when a radio is clicked
		$('input.radio').click(function(){
			$('#movenextbtn').show();
		});
 
	});
</script>

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

Please Log in to join the conversation.

Did you already participate in our customer survey?

Don't miss your chance for great prices.

Please click here to participate:

Start now

Start now!

Just create your account and start using Limesurvey today.

Register now