...

View Full Version : Limit amount enterable in a ContentEditable DIV



aspdotnetguy
07-22-2002, 03:18 PM
Hello,

I am looking for a way to gracefully limit the amount that can be typed in a contentEditable DIV that I am using for text editor, I tried a few things

1: Setting ContentEditable to false when the user gets to XXX Chars but this is not graceful as they can not do anything now

2: Doing a pop up when they get to XXX chars but this is ugly as every time they hit a key owhen > XXX Chars they are going to get a pop-up

3: Waiting tell they try and submit and then telling them this is ugly as it seems a little late

What I am wondering is if there is a way to get it to act like a "textbox" where the users just cant type anymore? It is for IE 6.0 only as it for an Intranet.

Any help would be appreciated, thanks in advance,

Lyndon

caldasgsm
07-22-2002, 03:43 PM
<div onkeypress="return (this.innerText.length >= 256 ? false : true )"

maybe something like this???

aspdotnetguy
07-22-2002, 03:50 PM
Perfect,

I will try and implement something like that, is there a way to allow the user to use the backspace, home, end, shift key, etc still though? I haven't used to mayn keyevents before.

This is so that if a user typed 50 chars and realized they have reached the maximum, they could take a out a work from a middle and ad an important word, just like a normal text box.

I think this solution has the potential to funciton just like this, I don't know if htere is a way to detect the backspace key though? Any more information would be appreciated.

Or would a key press of backspace take it to 256-1 which 255 and allow it? Hmm I guess I should try it, I am just waiting for my permissions on the server to be enabled again, I will try it and let you know as soon as I get a chance.

Thanks

aspdotnetguy
07-22-2002, 04:01 PM
:

jkd
07-22-2002, 07:41 PM
Originally posted by caldasgsm
<div onkeypress="return (this.innerText.length >= 256 ? false : true )"

maybe something like this???

Why the need for the ternary operator? All comparison operators return a boolean anyway:

onkeypress="return (this.innerText.length <= 256)"

aspdotnetguy
07-22-2002, 08:55 PM
Problem solved,

Thakn you for the solution gentlemen :)

caldasgsm
07-23-2002, 12:08 AM
All comparison operators return a boolean anyway:

that's cool I never had tough of that:o



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum