Read characters in a field dynamically

I would like to dynamically read the characters in the field of the text area of ​​the form, I know that there is a similar question about this, but I wonder if it can count from a certain number to 0, for example, when writing a tweet on Twitter.

This code can be in JavaScript, PHP, for me it does not matter.

+3
source share
2 answers

This will help you. Below is a tutorial - a demo is below:

Application:

<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 loan at www.reconn.us

Hope this helps.

+6
source

Using Javascript, use the KeyUp event handler and check the legnth property in the text box on each event.

: http://jsfiddle.net/nslr/C2CNS/

+1

All Articles