Textarea limit jscript not working in NS?

Results 1 to 3 of 3

Thread: Textarea limit jscript not working in NS?

  1. #1
    Join Date
    Dec 1969

    Default Textarea limit jscript not working in NS?

    I have a jscript from a site I found somewhere, and it works nicely on IE, but not at all on Netscape, at least on version 4.79. I tweaked it enough to get rid of that commonly seen "x characters left" box that we didn&#039;t want on our forms, but I&#039;m not familiar enough yet to know what needs to be done to it to get it to work on NS, if indeed it will at all. It may not, but I need to know that, too, if someone with a newer version of NS can tell me that.<BR><BR>The script is to stop a user from entering more than x number of characters in a textarea form field, a common enough request, and we do have a backup function in the next (non-test) program that counts the chars entered and alerts the user if too many were entered. We&#039;d rather catch them at the form, tho, if possible. Note I had to space out the tag code a bit below &#039;cause it was messing up this msg :)<BR><BR>&#060;SCRIPT Language = "JavaScript"&#062;<BR>&#060;!--<BR>function doleft1() {<BR>total = eval("30")<BR>char = eval(document.form.text1.value.length)<BR>left = eval(total - char)<BR>if (left &#060;= "-1")<BR>{<BR>var dif = eval(char - 30)<BR>var value = document.form.text1.value.substr(0,char-dif);<BR>document.form.text1.value = value;<BR>var left = "0"<BR>}<BR>}<BR>--&#062;<BR>&#060;/SCRIPT&#062;<BR>~<BR>&#060;F O R M NAME="form" method="POST" action="whatever.asp" &#062;<BR>&#060;T E X TAREA onkeyup="javascript:doleft1();" id="text1" name="tb1" Rows="3" Cols="25"&#062;&#060;/TEXTA R E A &#062;<BR>enter anything over 30 chars in the textbox to test it<BR>&#060;/form&#062;<BR>~<BR><BR>Appreciate any help! The current version of the test file can be seen at https://www.albemarle.org/its/obsolete/test/testtb3.asp<BR><BR>elaine pack<BR>epack@blue.unix.virginia.edu

  2. #2
    Join Date
    Dec 1969

    Default RE: Textarea limit jscript not working in NS?


  3. #3
    Join Date
    Dec 1969

    Default It's a stupid answer, though...

    That is, the second part is. Capturing keystrokes is a waste of code.<BR><BR>What do you do if the user simply does a COPY/PASTE into the textarea using the mouse???<BR><BR>Then there AREN&#039;T any keystrokes to capture!!!<BR><BR>A much more sensible way is to set a timer to check the length every quarter or half second. If the size is exceeded, give a nasty message and chop it back to the max. Simple as that.<BR><BR>&#060;FORM Name="TheForm"&#062;<BR>&#060;TEXTAREA Name="TheArea"&#062;&#060;/TEXTAREA&#062;<BR>...<BR>&#060;/FORM&#062;<BR><BR>&#060;SCRIPT&#062;<BR>function checkTheArea( )<BR>{<BR> var area = document.TheForm.TheArea;<BR> if ( area.value.length &#062; 3000 )<BR> {<BR> alert("You are allowed a maximum of 3000 characters for your message.");<BR> area.value = area.value.substring(0,3000);<BR> }<BR> // and do this again in half a second<BR> setTimeout("checkTheArea( )", 500);<BR>}<BR>// have to start it up the first time:<BR>checkTheArea( );<BR>&#060;/SCRIPT&#062;<BR>

Posting Permissions

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