You are viewing limited content. For full access, please sign in.

Question

Question

Word Count

asked on April 12, 2019 Show version history

Is this a way I can put a minimum word count in a multi line field? for example: we have a multi line field where an applicant needs to submit an essay. We request the essay to be a minimum of 150 words.... Or even if I can show a word count on the form?

 

any input would help! thanks

 

0 0

Answer

SELECTED ANSWER
replied on April 12, 2019 Show version history

Just re-read your request and realized you want to add a check on that field.

I'd still recommend what I wrote above, but change the text below the field to 'Word count (minimum 150): ' or similar.

Also, update the JS to this:

(function() {  
  function wordCount(essay) {
    return essay.split(' ')
    .filter(function(n) { return n != ''})
    .length;
  }
  
  $(document).ready(function() {    
    $('.Submit').attr('disabled', 'disabled');
    $('.essay textarea').on('input', function() {
      var count = wordCount($('.essay textarea').val());
      $('.essay label.cf-helptext.un-help').text('Word count (minimum 150): ' + count);
      if (count >= 150) {
        $('.Submit').removeAttr('disabled');
      }
      else {
        $('.Submit').attr('disabled', 'disabled');
      }
    });
  });
})();

I think that will be a little closer to what you're looking for.

4 0
replied on May 16, 2019

So the word count works on the form as the submitter types into the form, but the word count amount does not save on the stored form.. any ideas?

0 0
replied on November 6, 2023

Do you have tips for how to apply this on Forms 11?

0 0
replied on November 7, 2023

Hi Delilah,

 

I just tested, the above script should still work for Forms 11 with classic form designer. 

0 0

Replies

replied on April 12, 2019 Show version history

Hi Haylee,

First, I assume you're using a textarea to hold the essay text. Give it the class 'essay' and put the text 'Word count:' in the 'Text below field' field:

Add the following JavaScript under the CSS and JavaScript tab:

(function() {  
  function wordCount(essay) {
    return essay.split(' ')
    .filter(function(n) { return n != ''})
    .length;
  }
  $(document).ready(function() {
    $('.essay textarea').on('input', function() {
      var count = wordCount($('.essay textarea').val());
      $('.essay label.cf-helptext.un-help').text('Word count: ' + count);
    });
  });
})();

That should do it! As the user types, the word count will increment.

Best,

Rob

2 0
replied on April 12, 2019

YOU ARE MY HERO!!

0 0
replied on April 12, 2019

Glad to help! Please mark as the answer for others that may need the same solution in the future!

2 0
replied on May 17, 2023

Four years later and you're still making people's day! Thanks!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.