- Posts: 2
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Make "Submit" button appear only if people answer "Yes" for a Yes/No question
- sanzo_reload
- Topic Author
- Offline
- New Member
Less
More
12 years 8 months ago - 12 years 8 months ago #64932
by sanzo_reload
Make "Submit" button appear only if people answer "Yes" for a Yes/No question was created by sanzo_reload
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?
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: 12 years 8 months ago by sanzo_reload.
The topic has been locked.
- atiut
- Offline
- New Member
Less
More
- Posts: 1
- Thank you received: 0
12 years 8 months ago #64940
by atiut
Replied by atiut on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
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.
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 topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10126
- Thank you received: 3600
12 years 8 months ago #64948
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
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.
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.
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>
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
The topic has been locked.
- sanzo_reload
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
12 years 8 months ago #64957
by sanzo_reload
Replied by sanzo_reload on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
omg! It works!
Thank you so much..
I tried to do this for almost 6 hours, but nothing seems to be working~
Thank you so much..
I tried to do this for almost 6 hours, but nothing seems to be working~
The topic has been locked.
- bigbossben
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
11 years 5 months ago #90412
by bigbossben
Replied by bigbossben on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
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>
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 topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10126
- Thank you received: 3600
11 years 5 months ago #90414
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
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 $('#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
The topic has been locked.
- bigbossben
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
11 years 5 months ago #90415
by bigbossben
Replied by bigbossben on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
Thank you so much!!!
The topic has been locked.
- dweisser
- Offline
- Premium Member
Less
More
- Posts: 115
- Thank you received: 4
11 years 3 months ago #91559
by dweisser
Replied by dweisser on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
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
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 topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10126
- Thank you received: 3600
11 years 3 months ago #91626
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
LS 2.0 uses button elements instead of inputs for submit. Try this:
Code:
<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.
The topic has been locked.
- dweisser
- Offline
- Premium Member
Less
More
- Posts: 115
- Thank you received: 4
11 years 3 months ago #91645
by dweisser
Replied by dweisser on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
And, once again Tony comes through in the clutch.
Works absolutely perfectly.
I thank you.
- Nebraska David
Works absolutely perfectly.
I thank you.
- Nebraska David
The topic has been locked.
- Tomtefar
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
8 years 5 months ago #129472
by Tomtefar
Replied by Tomtefar on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
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?
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:
Code:<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>
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10126
- Thank you received: 3600
8 years 5 months ago #129515
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Make "Submit" button appear only if people answer "Yes" for a Yes/No question
LS 2.06 uses a newer version of jQuery so try this in the source of the Yes/No question:
Code:
<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.
The topic has been locked.