 |
 |
javascript: limit textarea input length. problem.
|
 |
|
 |
|
Mac Enthusiast
Join Date: Nov 2001
Location: Washington, DC 20009
Status:
Offline
|
|
I have a requirement to limit all textareas to 1000 characters to prevent issues with a varchar(1000) in our oracle database table. I've found enough Javascript code to piece together a function that limits the size. Here is what I have so far.
Code:
function limitText(field, count, limit)
{
if (field.value.length > limit)
field.value = field.value.substring(0, limit);
else
count.value = limit - field.value.length;
}
This works to stop the user from input more that 1000 characters. My problem is this: in Netscape, when the user hits the 1001st character, the function takes action to truncate the text, just as it should. All is fine and dandy except the cursor ends up at the first character position. If the user continues to type, unknowing of the 1000 character max, the input begins to be overwritten from the beginning. On IE, this problem does not occur, as the cursor remains at the end of the input string.
Does anyone have a work-around for this? Something to force the cursor to the end would probably be the most straightforward solution. TIA.
|
|
Just my $.02 :-)
Ti Powerbook 1Ghz w/ Superdrive ......and lovin' it! :)
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
I don't know of a way to do force the cursor to the end, but might you be able to use the alert() function to put up a dialog box indicating that they've reached the limit? This would trap the next few keystrokes the user tried to input, such that this wouldn't be a problem.
|
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Nov 2001
Location: Washington, DC 20009
Status:
Offline
|
|
Originally Posted by Millennium
I don't know of a way to do force the cursor to the end, but might you be able to use the alert() function to put up a dialog box indicating that they've reached the limit? This would trap the next few keystrokes the user tried to input, such that this wouldn't be a problem.
I attempted this approach, but Netscape doesn't even seem to acknowledge the alert(). I removed the bit of code to truncate so that it just notifies the user when he/she has reached 1000 characters.
Code:
if (field.value.length > limit) {
alert("You've reached the" + limit + " character limit.");
}
This works fine with IE, but does nothing under Netscape. What gives?
|
|
Just my $.02 :-)
Ti Powerbook 1Ghz w/ Superdrive ......and lovin' it! :)
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |