PDA

View Full Version : Form field limiter issues



MoGryph
12-07-2006, 08:27 PM
1) Script Title: Form field Limiter

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex16/limitinput.htm

3) Describe problem:
For the Text box input, a new line adds 2 characters, as opposed to one, when using IE (I don't have Netscape, or Opera to test it). I realize that this happens because IE recognizes a new line as a carriage return and line feed.

This can be corrected by using a regular expression replacement against the fields value, replacing \r with a null string- such as e.g. value.replace(/\r/g, "")

I'd show an example using the actual code, but I have trouble reading and updating code that isn't written with semi-colon statement terminators.

Another issue is that if you paste data into the field with a CTRL-V shortcut paste, and keep holding down the CTRL-V (to paste and paste and paste), it IS possible to select other text on the form, and blur focus from the field without the event occurring and leaving the value un-truncated.
Though I'm sure this would be rarely exploited, I think users should be aware of this.
The onBlur event of the field might be able to be used to catch this, but I haven't tried, so I'm not certain.

This of course, can be handled on the server side after the submission.


--------
Just a few more notes
--------
I realize that the page does not mention that Firefox is also compatible.
This script also works in Mozilla Firefox, however, Firefox correctly recognizes the crlf as a single character.

The main diff between FF and IE, is that FF will not replace the last characters in the string, until a Key up is registered, so if someone were to keep holding down a character, it would keep adding the character to the field until they lift it up, after which the field is truncated, but the 'character count' that is displayed shows "-1".
FF does also have the CTRL-V paste issue.

-Mo