Results 1 to 5 of 5

Thread: Restricting length of <textarea> in vbscript [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    2

    Restricting length of <textarea> in vbscript [RESOLVED]

    Hi pals, I'm new to this forum.

    I'm trying to limit the maximum character count of a <textarea> box in a html web form. I'm collecting user comments from that box, and I don't want excessive amount of text.

    I tried to check the length of the text with some client side vbscript. I checked the length of text whenever onKeyPress event is fired, But the problems are --

    - The text length returned by len() includes the return key counts (carriage return key + blank line, 2 extra count for every line break), but I need to count the exact number of characters only.

    - I tried to use a static variable to count how many times return key was pressed (If window.event.keyCode = 13 then ...). Afterwards, I subtract that variable from the total length to get the text length excluding the return key counts. But this will not work if the user decides to delete what he just typed in the textarea. The carriage return and blank lines will be deleted, but the return key count will remain the same.

    - I can't find a way to catch the keycode when a user presses backspace key. Even if I can, the user can still do selection with shift key and delete the whole chunk of text in just one stroke of backspace key.



    I've searched through some online resources and found client side codes to do that in javascript. But one of the requirements my school project is that I must use strictly vbscript only.

    Any help will be appreciated. Just a link to a web page or a forum thread will do. Thanks in advance.

    VB Code:
    1. <script language = "vbscript">
    2.  
    3. dim mintReturnKeyCount
    4.  
    5. sub txaInput_onKeyPress
    6.     dim lintLimit 'character limit
    7.     lintLimit = 10
    8.    
    9.     if window.event.keyCode = 13 then 'catch return key
    10.         mintReturnKeyCount = mintReturnKeyCount + 2
    11.     end if
    12.    
    13.     if len(txaInput.value) - mintReturnKeyCount >= lintLimit then
    14.         msgbox "Maximum length is " & lintLimit & " characters."
    15.         window.event.returnValue = false
    16.     end if
    17. end sub
    18.  
    19. </script>
    Last edited by maximwinter; Oct 3rd, 2002 at 11:31 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width