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

Question

Question

Word Count

asked on April 12 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 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.

3 0

Replies

replied on April 12 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

1 0
replied on April 12

YOU ARE MY HERO!!

0 0
replied on April 12

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

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

Sign in to reply to this post.