Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Limit amount enterable in a ContentEditable DIV

    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

  • #2
    New Coder
    Join Date
    Jul 2002
    Location
    Portugal
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <div onkeypress="return (this.innerText.length >= 256 ? false : true )"

    maybe something like this???

  • #3
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    :
    Last edited by aspdotnetguy; 07-22-2002 at 03:32 PM.

  • #5
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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)"

  • #6
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Problem solved,

    Thakn you for the solution gentlemen

  • #7
    New Coder
    Join Date
    Jul 2002
    Location
    Portugal
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    All comparison operators return a boolean anyway:
    that's cool I never had tough of that


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •