views:

198

answers:

1

I have textarea with rows="50" and cols="15". I want when it's going to wrap the words to simulate enter pressing,because I check when the user goes to new row with keydown and e.which==13 ,but the word wrap prevents me to check this. edit: Because I want to try to make something like online editor ,and I dynamicly count the rows like Bespin`s(bespin.mozillalabs.com ,left) rows counting.For this counting I detect when enter is pressed and add new number,but when word wrap is on - it counts wrong ,because when the words are wrapping enter isn't pressed.

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

<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>
+1  A: 

i don't know why you want to do this but you could use 2 "hacks":
1) count the amount of letters and if is == to 1 line of text add a \n
2) use a rich editor as ckeditor in minimal whiteout plugins and add the word wrap option (most of them have something like that)

shadow_of__soul