Tryit Editor on WebCheatSheet. How to Limit the Number of Characters in a Textarea or Text Field. This script allows you to set a limit on the number of characters a user can enter into a textarea or text field, like so: Step 1 - Create Function Insert the following code into the page head: <script language="javascript" type="text/javascript"> function limitText(limitField, limitCount, limitNum) { if (limitField.value.length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } else { limitCount.value = limitNum - limitField.value.length; } } </script> Step 2 - Create Text Area Use the following code to create the form and text area (if necessary, change the name of the form and text area to suit your needs): <form name="myform"><textarea name="limitedtextarea" onKeyDown="limitText(this.form.limitedtextarea,this.form.countdown,100);" onKeyUp="limitText(this.form.limitedtextarea,this.form.countdown,100);"></textarea><br><font size="1">(Maximum characters: 100)<br> You have <input readonly type="text" name="countdown" size="3" value="100"> characters left.
JavaScript: Form Validation. Any interactive web site has form input - a place where the users input different kind of information. This data is passed to ASP script, or some other technology and if the data contains an error, there will be a delay before the information travels over the Internet to the server, is examined on the server, and then returns to the user along with an error message.
If you run a validation of the user’s form input before the form is submitted, there will be no wait time and redundant load on the server. "Bad data" are already filtered out when input is passed to the server-based program. It also allows to simplify server-based program. Client side form validation usually done with javascript. For the majority of your users, JavaScript form validation will save a lot of time up front, but double-checking the data on the server remains necessary, in case the user has turned JavaScript off.
Form data that typically are checked by a JavaScript could be: validateFormOnSubmit ( ) return true;} JavaScript Form Validation. Web Marketing For Dummies, 2nd Edition:Book Information and Code Download.