admin管理员组文章数量:1310119
I would like to count characters in a form textarea field dynamically, I know there is a similar question about this but I am wondering if it can count from a certain number towards 0, as example while writing a tweet on Twitter.
This code could be in javascript, PHP, it doesn't really matter to me.
I would like to count characters in a form textarea field dynamically, I know there is a similar question about this but I am wondering if it can count from a certain number towards 0, as example while writing a tweet on Twitter.
This code could be in javascript, PHP, it doesn't really matter to me.
Share Improve this question edited May 2, 2019 at 11:52 Cœur 38.8k26 gold badges205 silver badges277 bronze badges asked Mar 21, 2011 at 14:33 Deniz ZoetemanDeniz Zoeteman 10.1k26 gold badges72 silver badges98 bronze badges 1- possible duplicate of jQuery - Count characters in textarea – Gabriele Petrioli Commented Mar 21, 2011 at 14:51
2 Answers
Reset to default 6This should help you out. Here is a tutorial regarding usage - a demo is found below:
Usage:
<input name="text" onKeyDown="CountLeft(this.form.text, this.form.left,50);"
onKeyUp="CountLeft(this.form.text,this.form.left,50);">
Javascript:
<SCRIPT LANGUAGE="JavaScript">
function CountLeft(field, count, max)
{
if (field.value.length > max)
field.value = field.value.substring(0, max);
else
count.value = max - field.value.length;
}
</SCRIPT>
Demo - Credit to www.reconn.us
Hope this helps.
With Javascript, use the KeyUp event handler, and check for the legnth-property on your text field on every event.
Example: http://jsfiddle/nslr/C2CNS/
本文标签: phpCount characters in field dynamicallyStack Overflow
版权声明:本文标题:php - Count characters in field dynamically - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741851874a2401118.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论