Click to See Complete Forum and Search --> : Moving the cursor


Webskater
05-22-2003, 09:15 AM
I have a textarea on a form and I need to limit the number of characters that people enter. I have a script that puts an alert on the screen that says ('No more than five hundred characters allowed. Please abbreviate.') After the alert the focus is put back on the textarea. I would like to move the cursor to the 500th character. Is this possible? Thanks for any help.

Gollum
05-22-2003, 09:26 AM
The only thing that does what you want that I can see is a thing called "TextRange" which is only supported on IE4(win) and above.

The next best option is to cut the length of the text area whenever it goes over the limit. Users will soon catch on.

Jona
05-22-2003, 09:29 AM
<html><head><title></title>
<script type="text/javascript">
<!--
var maxLength = 5000;

function countChars(box){
if(box.length>maxLength){
alert("You cannot have more than 5,000 characters in the text area."); return false;}
return true;
}
//-->
</script></head>
<body>
<form name="f" action=""><div>
<textarea name="area" rows="5" cols="15" onChange="countChars(this)"></textarea>
</div></form>
</body></html>

Webskater
05-22-2003, 10:31 AM
Thanks for your replies. I had a look at TextRange on the Microsoft site and it sounds as though it will do the trick.