Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Hide the Next Button Until a Particular Character/Word Count is Achieved

  • TreyBrasher
  • TreyBrasher's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago #185786 by TreyBrasher
In order to get a deep response, I would like to code a question so that the 'next' button will not appear until a minimum character/word count is reached. I have very little coding experience but spent the last few hours trying to piece together code other people have written to first hide the 'next' button, and then display it again after the character count is reached. The code I attempted is attached. It is written in the question code. My skill level is obviously not up to snuff and I cannot find a solution in the forum. Please help! Thanks in advance.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago #185790 by tpartner
LimeSurvey version?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • TreyBrasher
  • TreyBrasher's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago #185792 by TreyBrasher
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 9 months ago - 4 years 9 months ago #185811 by tpartner
You need (among other things) to incorporate a listener on the textarea. (adjust the minCharacters variable as required)

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
    var thisTextArea = $('textarea:eq(0)', thisQuestion);
 
    // Set minimum characters
    var minCharacters = 10;
 
    function handleCharacterCount() {
      var thisVal = $.trim($(thisTextArea).val());
      var thisCount = thisVal.length;
 
      $('.character-count', thisQuestion).text(thisCount);
 
      if(thisCount <= minCharacters) {
        $('#ls-button-submit').prop('disabled', true);
      }
      else {
        $('#ls-button-submit').prop('disabled', false);
      }
    }
 
    // Initial state
    handleCharacterCount();
 
    // Listener on the textarea
    $(thisTextArea).on('keyup change', function(e) {
      handleCharacterCount();
    });
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...6-19.lss
File Size:15 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 9 months ago by tpartner.
The following user(s) said Thank You: cdorin
The topic has been locked.
  • TreyBrasher
  • TreyBrasher's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 9 months ago #185846 by TreyBrasher
Wow, works perfectly. Your work is very much appreciated, I thank you deeply. Can't wait to conduct some research with this survey!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose