|
-
Oct 2nd, 2002, 02:09 AM
#1
Thread Starter
New Member
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:
<script language = "vbscript">
dim mintReturnKeyCount
sub txaInput_onKeyPress
dim lintLimit 'character limit
lintLimit = 10
if window.event.keyCode = 13 then 'catch return key
mintReturnKeyCount = mintReturnKeyCount + 2
end if
if len(txaInput.value) - mintReturnKeyCount >= lintLimit then
msgbox "Maximum length is " & lintLimit & " characters."
window.event.returnValue = false
end if
end sub
</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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|