Forum Moderators: open

Message Too Old, No Replies

limit textarea question

         

syktek

6:50 pm on Jan 18, 2007 (gmt 0)

10+ Year Member



<textarea name="comment" onkeypress="return (this.value.length < 241);"></textarea>

using the code above i am successfully able to limit the text area to 240 characters, the question i have is in IE this works fine but in firefox after i reach my 240 character limit the textarea is no longer functional.

just not understanding why this happens in firefox, hoping someone could shed some light for me.

thanks,
stephen

Fotiman

10:33 pm on Jan 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Browsers have default behaviors for some events. For example, pressing F5 in your browser triggers the browser's Refresh/Reload. This action can be cancelled. It would seem that in IE, returning false in the event handler function does not stop the event's default behavior from being triggered, but in Firefox it does.

Therefore, once you reach your limit, pressing a key is going to return false, stopping the default behavior. So if you try to press backspace to remove a character, it's going to return false before the default behavior happens.