Re: textarea limit

From: Date: Fri, 11 Apr 2003 08:28:48 +0000
Subject: Re: textarea limit
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-143617@lists.php.net to get a copy of this message
Hello. There exists a way but in JavaScript. I have used this funtion once. The function checks the size of the string value, and if the user wants to add more chars, the function don't allow that and sends an alert to the user. This is the output for getting an idea on how to include the text on a php file. Be careful if you include this function in your php code for the quotes. The strings on the JavaScript code MUST be in as appears here (or delete the comments). --------------[CUT HERE]-------------- <html> <head> <meta http-equiv="Content-Type" content="text/html"> <title>Title</title> <script language="JavaScript" type="text/javascript"> // Script made by Mario Soto <mario_s@amigo.net.gt> var oldtext=""; //Sets up a variable for a control string. All chars > max_length are deleted var max_lenght=254; //Max lenght of the string function h_sizetest(){ //Function that tests the max lenght on a string and don't allow //more chars of the defined at 'max_length' var var textareastring=textareainput.value; //Loads the string onto a variable if(textareastring.length <= max_lenght){ //If can input more chars oldtext=textareastring; //Reset the variable with the new value }else{ //If the textarea is full (no more chars allowed) textareainput.value=oldtext; //Reset the value on the textarea alert("The string maxium size is: "+max_lenght+" chars"); //Alerts the user for an invalid action } //end if } //end h_sizetest() </script> </head> <body> ****** Your page here ******** <br> <textarea rows="10" cols="40" name="textareainput" onkeyup= "h_sizetest()"> </textarea> <br> ****** The rest of your page here ******** </body> </html> --------------[CUT HERE]-------------- Mario Soto mario_s@amigo.net.gt -.-.-.- ----- Original Message ----- From: "carol" <carol@romag.ro> To: <php-general@lists.php.net> Sent: Thursday, April 10, 2003 12:51 AM Subject: [PHP] textarea limit I try to limit the number of characters in a textarea to 254 but I=20 can't. Could anyone help me? pls...

« previous php.general (#143617) next »