0

I use the function below to control the maximum row of textarea.

<textarea wrap="hard" name="" class="jua" onkeydown="return limitLines(this, event)" id="text_01_01" rows="2" placeholder=""></textarea>
function limitLines(obj, e){
    console.log("test");
    let numberOfLines = (obj.value.match(/\n/g) || []).length + 1;
    let maxRow = obj.rows;
    if (e.which === 13 && numberOfLines === maxRow){
        return false;
    }
}

but this way, this method cannot detect line breaks by width. I want to count even rows that automatically wrap.

Sorry for my poor English skills. Thanks

박근영
  • 3
  • 1

1 Answers1

0

I don't believe determining the count of characters on a wrapped line is possible at all via JavaScript. Wrapping is a purely visual behavior from the JS perspective. I would suggest giving the <textarea> a static width and disable word wrap all together (see this answer).