Welcome, Guest
Username: Password: Remember me

TOPIC: Make "Submit" button appear only if people answer "Yes" for a Yes/No question

Make "Submit" button appear only if people answer "Yes" for a Yes/No question 2 years 11 months ago #64932

So what I'm trying to do is to have one last page with this question:

You have reached the end of the survey. Please note that once the "SUBMIT" button is clicked, your response is final and will be sent to the management.

Are you sure you want to submit the survey?

- Yes/No answer

The "SUBMIT" button will be disabled when page first load and will only be enabled when the person click "YES".

Is there any way to do this?
Last Edit: 2 years 11 months ago by sanzo_reload.
The administrator has disabled public write access.

Re: Make "Submit" button appear only if people answer "Yes" for a Yes/No question 2 years 11 months ago #64940

  • atiut
  • atiut's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 76
  • Thank you received: 2
  • Karma: 1
Hmm.. you can try to use {SUBMITBUTTON} (see docs.limesurvey.org/The+template+editor&...+LimeSurvey#Keywords), maybe in a hidden/ conditional question.

However you would still need to disable somehow the {NAVIGATOR} button from navigator.pstpl in the theme template. On the last page {NAVIGATOR} becomes a submit button. You could try to remove it from the template then insert it on every page except the last, where you would have a conditioned {SUBMITBUTTON}. Not very elegant though, and there could be some interactions I am missing.
The administrator has disabled public write access.

Re: Make "Submit" button appear only if people answer "Yes" for a Yes/No question 2 years 11 months ago #64948

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
1) Set up your survey to use JavaScript.

2)Add the following script to the source of the Yes/No question.

The script initially disables the Next/Submit button and puts listeners on Yes/No radios to toggle the "disabled" attribute.
<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');
		});
 
	});
 
</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.
The following user(s) said Thank You: sanzo_reload

Re: Make "Submit" button appear only if people answer "Yes" for a Yes/No question 2 years 11 months ago #64957

omg! It works!
Thank you so much..
I tried to do this for almost 6 hours, but nothing seems to be working~
The administrator has disabled public write access.

Re: Make "Submit" button appear only if people answer "Yes" for a Yes/No question 1 year 7 months ago #90412

  • bigbossben
  • bigbossben's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
Hi, thank you so much for that script.
If the code of a question is 15675X876X8765, how do I replace "input.radio" for that question code? I try to replace it and it doesn't work.

<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
$('15675X876X8765[value="Y"]').click(function(){
$('input[type="submit"]').attr('disabled', '');
});
$('15675X876X8765[value="N"]').click(function(){
$('input[type="submit"]').attr('disabled', 'disabled');
});

});

</script>
The administrator has disabled public write access.

Re: Make "Submit" button appear only if people answer "Yes" for a Yes/No question 1 year 7 months ago #90414

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
<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
		$('#question8765 input.radio[value="Y"]').click(function(){
			$('input[type="submit"]').attr('disabled', '');
		});
		$('#question8765 input.radio[value="N"]').click(function(){
			$('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.
The following user(s) said Thank You: bigbossben

Re: Make "Submit" button appear only if people answer "Yes" for a Yes/No question 1 year 7 months ago #90415

  • bigbossben
  • bigbossben's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
Thank you so much!!!
The administrator has disabled public write access.

Re: Make "Submit" button appear only if people answer "Yes" for a Yes/No question 1 year 6 months ago #91559

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 196
  • Thank you received: 5
  • Karma: 5
The solution looks so simple - but for the life of me I cannot get this to work on my survey.

I have enabled javascript:
Filter HTML for XSS: No

I too have a yes/no question type:
Type: Yes/No

I have copied this code:

<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');
});

});

</script>

I then updated this code to reflect my particular question number.

<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
$('#question199 input.radio[value="Y"]').click(function(){
$('input[type="submit"]').attr('disabled', '');
});
$('#question199 input.radio[value="N"]').click(function(){
$('input[type="submit"]').attr('disabled', 'disabled');
});

});

</script>

And nothing. Any thoughts? Much appreciated.
David
The administrator has disabled public write access.

Re: Make "Submit" button appear only if people answer "Yes" for a Yes/No question 1 year 6 months ago #91626

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
LS 2.0 uses button elements instead of inputs for submit. Try this:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		// Initially disable the Next/Submit button
		$('button[type="submit"]').attr('disabled', 'disabled').addClass('ui-state-disabled');
 
		// Listeners on Yes/No radios to toggle the Next/Submit button
		$('#question199 input.radio[value="Y"]').click(function(){
			$('button[type="submit"]').attr('disabled', '').removeClass('ui-state-disabled');
		});
		$('#question199 input.radio[value="N"]').click(function(){
			$('button[type="submit"]').attr('disabled', 'disabled').addClass('ui-state-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: Make "Submit" button appear only if people answer "Yes" for a Yes/No question 1 year 6 months ago #91645

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 196
  • Thank you received: 5
  • Karma: 5
And, once again Tony comes through in the clutch.
Works absolutely perfectly.
I thank you.
- Nebraska David
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.155 seconds
Donation Image