Welcome, Guest
Username: Password: Remember me

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

How can I stop the page reloading if mandatory question not answered? 1 year 4 months ago #89552

  • Melarish
  • Melarish's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
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;
				}
			});
The administrator has disabled public write access.

Aw: How can I stop the page reloading if mandatory question not answered? 1 year 4 months ago #89597

  • jelo
  • jelo's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 389
  • Thank you received: 40
  • Karma: 15
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?
The administrator has disabled public write access.

Re: How can I stop the page reloading if mandatory question not answered? 1 year 4 months ago #89635

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Aw: How can I stop the page reloading if mandatory question not answered? 1 year 4 months ago #89646

  • Melarish
  • Melarish's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
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
The administrator has disabled public write access.

Re: Aw: How can I stop the page reloading if mandatory question not answered? 1 year 4 months ago #89652

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
...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.

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.
Moderators: ITEd
Time to create page: 0.121 seconds
Donation Image