hi
i have a text area where i want to limit the number of charactersin each line.
for example if the user enters more than 50 caharacters it should automatically move the cursor to the next line
thanks

I do not know if there is a simple way. But at this moment here what you can do.

Write a event handler for onkeyup for your text area and count for every keypress if count exceeds 50 then append '\n'(new line character) by yourself.

thats it.
Your js keyhandler will look somthing like this:-

var count = 0;
function keypress (e) {
     if(count>=50) {
           document.getElementById('textarea_id').value = document.getElementById('textarea_id').value + '\n';
           count = 0;
     } else {
           count++;
     }
}

Of course its working man. I tried it with document.getElementById('id of textarea')

What you want? That a working code is delivered to you so that you can sit back and rest.

tried something like this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript" type="text/javascript">
<!--
var count = 0;
function ress(){

if(count>=5) {
document.getElementById('textarea_id').value = document.getElementById('textarea_id').value + '\n';
count = 0;
} else {
count++;
}
}
//-->
</script>
</head>

<body>
<form>
<textarea name="textarea_id" onkeypress="ress();"></textarea>
</form>
</body>
</html>

in the function you have passed a variable called 'e'...wat is tat for

This article has been dead for over six months. Start a new discussion instead.