Specify word wrap in textarea

I have textarea with lines = "50" and cols = "15". I want, when this leads to the completion of words to simulate typing by pressing, because I check when the user goes to a new line with keydown and e.which == 13 , but word wrapping does not allow me to check this, change : Because I want try to make something like an online editor, and I am dynamically counting lines, such as Bespin`s line counting (bespin.mozillalabs.com, left). For this count, I detect when input is entered and a new number is added, but when word wrap is on, it is erroneous because when the words wrapping enter are not pressed.

Edit 2 : I found a script that does what I want, but how to simulate a button click?

<script language="javascript" type="text/javascript">
var ijk = 0;
function txt_ara()
{
//alert("1");
//alert(document.getElementById("email").value.length);
//var ijk = 0;
//var incr = 2;
if(document.getElementById("email").value.length <= 59)
{
if(document.getElementById("email").value.length == 59)
{
document.getElementById("email").value += "\n";
}
}
else
{
var lkm = "";
if(ijk == 0)
{
lkm = parseInt(document.getElementById("email").value.length % 120);
}
else
{
lkm = parseInt(document.getElementById("email").value.length % 60);
}
if(lkm == 0)
{
ijk = 1;
document.getElementById("email").value += "\n";
}
}
}
</script>
<textarea name="email" id="email" class="txtField1" cols="60" rows="26" wrap="off" onkeyup="txt_ara();" onkeydown="txt_ara();"></textarea>
+3
source share
1 answer

I don’t know why you want to do this, but you can use 2 "hacks":
1) count the number of letters, and if there is == up to 1 line of text, add \ n
2) use a rich editor like ckeditor in minimal plugins and add word wrap option (most of them have something similar)

+1
source

Source: https://habr.com/ru/post/1750817/


All Articles