0

Hello i have an about me field on a profile page i created, but noticed that i cant copy and paste words from other documents even when my max length is set to 1000 words, When i copy and paste in the text area , it takes in 50 words or so. My about length in the database is set 2000.Below is what i have in my form. Any help offered is deeply appreciated

<div class="form-group">
 <label for="about">About Me</label>
<textarea name="about" rows="3" maxlength="1000" class="form-control" id="about"></textarea>
</div> 

enter image description here

  • Maybe you can find the answer here https://stackoverflow.com/questions/17909646/counting-and-limiting-words-in-a-textarea – Savado Jun 16 '20 at 07:44

2 Answers2

0

The tag maxlength defines the number of max characters and not max words.

Perhaps your text is more than 1000 characters so it does not work

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
BeeTheKay
  • 319
  • 2
  • 15
0

The maxlength attribute defines the maximum number of characters (as UTF-16 code units) the user can enter into an or .

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/maxlength

I created a simple example when the maximum number of words is 5:

const input = document.getElementById('textArea');
const textContent = [];
let maxWords = 5;

function separateWords(text, e){
 let words = text.split(" ");
  
 if (words.length >= maxWords + 1) {
   input.setAttribute('maxLength',words.join(" ").length - 1);
    return words.join(" ").trim();
  } else {
  return words.join(" ");
  }
};

input.addEventListener('input', function()
{
console.log(separateWords(input.value));
});
<div>
<p>
Type something (max 5 words):
</p>
<textarea id="textArea" value=""></textarea>
</div>
Lucas L.
  • 407
  • 3
  • 9