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

More
6 years 1 month ago - 6 years 1 month ago #64932 by sanzo_reload
sanzo_reload created the topic: Make "Submit" button appear only if people answer "Yes" for
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: 6 years 1 month ago by sanzo_reload.

Please Log in to join the conversation.

More
6 years 1 month ago #64940 by atiut
atiut replied the topic: Make "Submit" button appear only if people answer "Yes" for
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.

Please Log in to join the conversation.

More
6 years 1 month ago #64948 by tpartner
tpartner replied the topic: Make "Submit" button appear only if people answer "Yes" for
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.
The following user(s) said Thank You: sanzo_reload

Please Log in to join the conversation.

More
6 years 1 month ago #64957 by sanzo_reload
sanzo_reload replied the topic: Make "Submit" button appear only if people answer "Yes" for
omg! It works!
Thank you so much..
I tried to do this for almost 6 hours, but nothing seems to be working~

Please Log in to join the conversation.

More
4 years 10 months ago #90412 by bigbossben
bigbossben replied the topic: Make "Submit" button appear only if people answer "Yes" for
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>

Please Log in to join the conversation.

More
4 years 10 months ago #90414 by tpartner
tpartner replied the topic: Make "Submit" button appear only if people answer "Yes" for
<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.
The following user(s) said Thank You: bigbossben

Please Log in to join the conversation.

More
4 years 10 months ago #90415 by bigbossben
bigbossben replied the topic: Make "Submit" button appear only if people answer "Yes" for
Thank you so much!!!

Please Log in to join the conversation.

More
4 years 8 months ago #91559 by dweisser
dweisser replied the topic: Make "Submit" button appear only if people answer "Yes" for
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

Please Log in to join the conversation.

More
4 years 8 months ago #91626 by tpartner
tpartner replied the topic: Make "Submit" button appear only if people answer "Yes" for
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.

Please Log in to join the conversation.

More
4 years 8 months ago #91645 by dweisser
dweisser replied the topic: Make "Submit" button appear only if people answer "Yes" for
And, once again Tony comes through in the clutch.
Works absolutely perfectly.
I thank you.
- Nebraska David

Please Log in to join the conversation.

More
1 year 10 months ago #129472 by Tomtefar
Tomtefar replied the topic: Make "Submit" button appear only if people answer "Yes" for
Old thread but I want exactly the same thing but I cannot get it to work. I have used your code and changed the question ID to mine. The submit button is diabled but when I choose Yes it does not enable. I am using a a Yes/No question.

I am running 2.06+, has anything changed that makes this not work anymore?

tpartner wrote: 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>

Please Log in to join the conversation.

More
1 year 10 months ago #129515 by tpartner
tpartner replied the topic: Make "Submit" button appear only if people answer "Yes" for
LS 2.06 uses a newer version of jQuery so try this in the source of the Yes/No question:

<script type="text/javascript" charset="utf-8">		
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Initially disable the Next/Submit button
		$('#movenextbtn, #movesubmitbtn').prop('disabled', 'true').addClass('ui-state-disabled');
 
		// Listeners on Yes/No radios to toggle the Next/Submit button
		$('input.radio[value="Y"]', thisQuestion).click(function(){
			$('#movenextbtn, #movesubmitbtn').prop('disabled', '').removeClass('ui-state-disabled');
		});
		$('input.radio[value="N"]', thisQuestion).click(function(){
			$('#movenextbtn, #movesubmitbtn').prop('disabled', 'true').addClass('ui-state-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
1 year 10 months ago #129535 by Tomtefar
Tomtefar replied the topic: Make "Submit" button appear only if people answer "Yes" for

tpartner wrote: LS 2.06 uses a newer version of jQuery so try this in the source of the Yes/No question:

<script type="text/javascript" charset="utf-8">		
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Initially disable the Next/Submit button
		$('#movenextbtn, #movesubmitbtn').prop('disabled', 'true').addClass('ui-state-disabled');
 
		// Listeners on Yes/No radios to toggle the Next/Submit button
		$('input.radio[value="Y"]', thisQuestion).click(function(){
			$('#movenextbtn, #movesubmitbtn').prop('disabled', '').removeClass('ui-state-disabled');
		});
		$('input.radio[value="N"]', thisQuestion).click(function(){
			$('#movenextbtn, #movesubmitbtn').prop('disabled', 'true').addClass('ui-state-disabled');
		});
 
    });
</script>



Works perfectly, thank you!

Please Log in to join the conversation.

More
10 months 3 days ago #146122 by bdeprez
bdeprez replied the topic: Make "Submit" button appear only if people answer "Yes" for
Hi Tony,

I may be overlooking something but does this code work in 2.57? I added it and it neatly disabled the submit button but it doesn't enable it when I select "Yes"...

Thanks,
B.

Please Log in to join the conversation.

More
10 months 2 days ago #146139 by tpartner
tpartner replied the topic: Make "Submit" button appear only if people answer "Yes" for
Try this - it should handle both button group and radio group layouts.

<script type="text/javascript" charset="utf-8">		
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Initially disable the Next/Submit button
		$('#movenextbtn, #movesubmitbtn').prop('disabled', 'true').addClass('ui-state-disabled');
 
		// Listeners on Yes/No radios to toggle the Next/Submit button
		$('input.radio[value="Y"], label[id$="X{QID}Y"]', thisQuestion).click(function(){
			$('#movenextbtn, #movesubmitbtn').prop('disabled', '').removeClass('ui-state-disabled');
		});
		$('input.radio[value="N"], label[id$="X{QID}N"]', thisQuestion).click(function(){
			$('#movenextbtn, #movesubmitbtn').prop('disabled', 'true').addClass('ui-state-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.

Start now!

Just create your account and start using Limesurvey today.

Register now