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
  • sanzo_reload's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 6 months ago - 12 years 6 months ago #64932 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?
Last edit: 12 years 6 months ago by sanzo_reload.
The topic has been locked.
More
12 years 6 months ago #64940 by atiut
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 topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 6 months ago #64948 by tpartner
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.
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
  • sanzo_reload's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 6 months ago #64957 by sanzo_reload
omg! It works!
Thank you so much..
I tried to do this for almost 6 hours, but nothing seems to be working~
The topic has been locked.
More
11 years 2 months ago #90412 by bigbossben
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 topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 2 months ago #90414 by tpartner
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.
More
11 years 2 months ago #90415 by bigbossben
Thank you so much!!!
The topic has been locked.
More
11 years 1 month ago #91559 by dweisser
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 topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 month ago #91626 by tpartner
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.
More
11 years 1 month ago #91645 by dweisser
And, once again Tony comes through in the clutch.
Works absolutely perfectly.
I thank you.
- Nebraska David
The topic has been locked.
More
8 years 3 months ago #129472 by Tomtefar
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:

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
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 2 months ago #129515 by tpartner
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.

Lime-years ahead

Online-surveys for every purse and purpose