| | |
Textarea characters limit
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2009
Posts: 1
Reputation:
Solved Threads: 0
Hi,
I want to limit the characters in the textarea to 400...
i found this script but i dont know how to implement in my script...
this is the script:
<html><head>
<title>(Type a title for your page here)</title>
<script language=JavaScript>
<!--
function check_length(my_form)
{
maxLen = 50; // max number of characters allowed
if (my_form.my_text.value.length >= maxLen) {
// Alert message if maximum limit is reached.
// If required Alert can be removed.
var msg = "You have reached your maximum limit of characters allowed";
alert(msg);
// Reached the Maximum length so trim the textarea
my_form.my_text.value = my_form.my_text.value.substring(0, maxLen);
}
else{ // Maximum length not reached so update the value of my_text counter
my_form.text_num.value = maxLen - my_form.my_text.value.length;}
}
//-->
</script>
</head>
<body>
<form name=my_form method=post>
<textarea onKeyPress=check_length(this.form); onKeyDown=check_length(this.form); name=my_text rows=4 cols=30></textarea>
<br>
<input size=1 value=50 name=text_num> Characters Left
</form>
</body>
</html>
and my script is:
<?php
class FormTextarea extends FormElement {
var $cols;
var $rows;
var $value;
function FormTextarea($f) {
$this->setCaption($f['caption']);
$this->setName($f['name']);
list($rows, $cols) = $f['size'] ? explode('x',$f['size']) : array(10,50);
$this->rows = intval($rows);
$this->cols = intval($cols);
$this->value = $f['value'];
}
function getRows() {
return $this->rows;
}
function getCols() {
return $this->cols;
}
function getValue() {
return $this->value;
}
function render() {
return '<textarea class="fields" name="'.$this->getName().'" id="'.$this->getName().'" rows="'.$this->getRows().'" cols="'.$this->getCols().'"'.$this->getExtra().'>'.$this->getValue().'</textarea>';
}
}
?>
Please help me with this... i really do not know php.
English is not my language... so sorry for mistakes.
I want to limit the characters in the textarea to 400...
i found this script but i dont know how to implement in my script...
this is the script:
<html><head>
<title>(Type a title for your page here)</title>
<script language=JavaScript>
<!--
function check_length(my_form)
{
maxLen = 50; // max number of characters allowed
if (my_form.my_text.value.length >= maxLen) {
// Alert message if maximum limit is reached.
// If required Alert can be removed.
var msg = "You have reached your maximum limit of characters allowed";
alert(msg);
// Reached the Maximum length so trim the textarea
my_form.my_text.value = my_form.my_text.value.substring(0, maxLen);
}
else{ // Maximum length not reached so update the value of my_text counter
my_form.text_num.value = maxLen - my_form.my_text.value.length;}
}
//-->
</script>
</head>
<body>
<form name=my_form method=post>
<textarea onKeyPress=check_length(this.form); onKeyDown=check_length(this.form); name=my_text rows=4 cols=30></textarea>
<br>
<input size=1 value=50 name=text_num> Characters Left
</form>
</body>
</html>
and my script is:
<?php
class FormTextarea extends FormElement {
var $cols;
var $rows;
var $value;
function FormTextarea($f) {
$this->setCaption($f['caption']);
$this->setName($f['name']);
list($rows, $cols) = $f['size'] ? explode('x',$f['size']) : array(10,50);
$this->rows = intval($rows);
$this->cols = intval($cols);
$this->value = $f['value'];
}
function getRows() {
return $this->rows;
}
function getCols() {
return $this->cols;
}
function getValue() {
return $this->value;
}
function render() {
return '<textarea class="fields" name="'.$this->getName().'" id="'.$this->getName().'" rows="'.$this->getRows().'" cols="'.$this->getCols().'"'.$this->getExtra().'>'.$this->getValue().'</textarea>';
}
}
?>
Please help me with this... i really do not know php.
English is not my language... so sorry for mistakes.
•
•
Join Date: May 2009
Posts: 5
Reputation:
Solved Threads: 1
javacript code
Form Field and countdown
PHP Syntax (Toggle Plain Text)
<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>
Form Field and countdown
PHP Syntax (Toggle Plain Text)
<textarea name="limitedtextfield" class="where" onkeydown="limitText(this.form.limitedtextfield,this.form.countdown,150);" onkeyup="limitText(this.form.limitedtextfield,this.form.countdown,150);"><?=$_REQUEST['limitedtextfield'];?></textarea> <span class="limit">(Maximum characters: <input name="countdown" type="text" value="150" size="1" readonly>)
If you at first you don't succeed, quickly deny you were even trying!
•
•
•
•
Please help me with this... i really do not know php.
html Syntax (Toggle Plain Text)
<html><head> <title>(Type a title for your page here)</title> <script language=JavaScript> <!-- function check_length(my_form) { maxLen = 400; // max number of characters allowed if (my_form.my_text.value.length > = maxLen) { // Alert message if maximum limit is reached. // If required Alert can be removed. var msg = "You have reached your maximum limit of characters allowed"; alert(msg); // Reached the Maximum length so trim the textarea my_form.my_text.value = my_form.my_text.value.substring(0, maxLen); } else{ // Maximum length not reached so update the value of my_text counter my_form.text_num.value = maxLen - my_form.my_text.value.length;} } //--> </script> </head> <body> <form name=my_form method=post> <textarea onKeyPress=check_length(this.form); onKeyDown=check_length(this.form); name=my_text rows=8 cols=60></textarea> <br> <input size=1 value=400 name=text_num readonly> Characters Left </form> </body> </html>
Last edited by cwarn23; May 3rd, 2009 at 9:38 pm.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - MacGyver Fan
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - MacGyver Fan
•
•
Join Date: Apr 2009
Posts: 257
Reputation:
Solved Threads: 37
I also have similar code. This is very good. Try it.
PHP Syntax (Toggle Plain Text)
<script language = "Javascript"> maxL=400; var bName = navigator.appName; function taLimit(taObj) { if (taObj.value.length==maxL) return false; return true; } function taCount(taObj,Cnt) { objCnt=createObject(Cnt); objVal=taObj.value; if (objVal.length>maxL) objVal=objVal.substring(0,maxL); if (objCnt) { if(bName == "Netscape"){ objCnt.textContent=maxL-objVal.length;} else{objCnt.innerText=maxL-objVal.length;} } return true; } function createObject(objId) { if (document.getElementById) return document.getElementById(objId); else if (document.layers) return eval("document." + objId); else if (document.all) return eval("document.all." + objId); else return eval("document." + objId); } </script> <form name="myfrm" id="myfrm" method="post"> <textarea cols="60" rows="3" name="short_desc" onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')"> </textarea> <font color="#006600">Max. Length: <span id="myCounter">400</span> </font> </form>
Last edited by BzzBee; May 4th, 2009 at 12:37 am.
![]() |
Similar Threads
- PLS I NEED YOUR HELP! Help on Reading and Editing of already Written CODE on php! (PHP)
- Using PHP/HTML to update informationin MySQL (PHP)
Other Threads in the PHP Forum
- Previous Thread: sync database localhost to hosting data
- Next Thread: Fatching different lines
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array back beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error file files filter folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm mod_rewrite multiple mysql navigation oop parse parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms snippet soap source space sql structure syntax system table thesishelp tutorial update upload url validation validator variable video web xml youtube






