JavaScript real-time display limit character input number and give hints

Source: Internet
Author: User
Tags truncated

JS statistics text box string, and real-time display the remaining characters, effect such as this blog comment word limit effect, share here, in the upload text works, I believe this will have a good effect on the user experience.
The code is relatively simple:

JavaScript code 01

The code is as follows Copy Code
. <script language= "JavaScript" >
<!--//
function textcounter (field, Countfield, Maxlimit) {
Define functions, pass in 3 parameters, respectively, the name of the form area, the form field element name, character limit;
if (Field.value.length > Maxlimit)
If the number of characters in the element area is greater than the maximum number of characters, truncated by the largest character;
Field.value = field.value.substring (0, Maxlimit);
Else
Displays the remaining number of characters in the Register text box;
Countfield.value = Maxlimit-field.value.length;
}
-->
</script>

Full instance

The code is as follows Copy Code

<table border= "0" cellpadding= "0" style= "border-style:solid; border-width:1px; padding:1px; Border-collapse:collapse "bordercolor=" #CCCCCC "width=" 100% "height=" 184 ">

<form action= "return1_w.php" method= "POST" target= "_blank" style= "margin:0px"; padding:0px; " >
<tr>
&LT;TD width= "height=" ><div align= "right" style= "font-size:12px" > Username:</div></td>
&LT;TD height= ">&nbsp;&nbsp;"
<input readonly= "readonly" type= "text" name= "Remlen" size= "4" maxlength= "3" value= "he"/>
Characters (you can give me comments or suggestions here, oh ^_^) </td>
</tr>
<tr>
&LT;TD width= "height=" ><script language= "JavaScript" >
<!--//
function textcounter (field, Countfield, Maxlimit) {
Define functions, pass in 3 parameters, respectively, the name of the form area, the form field element name, character limit;
if (Field.value.length > Maxlimit)
If the number of characters in the element area is greater than the maximum number of characters, truncated by the largest character;
Field.value = field.value.substring (0, Maxlimit);
Else
Displays the remaining number of characters in the Register text box;
Countfield.value = Maxlimit-field.value.length;
}
-->
</script>
<div align= "Right" style= "font-size:12px" > Reply content:</div></td>
&LT;TD width= "396" height= "><textarea rows=" "4" name= "Neirong" cols= "onkeydown=" Textcounter (   this.form.neirong,this.form.remlen,150); " Onkeyup= "Textcounter (this.form.neirong,this.form.remlen,150);" > </textarea></td>
</tr>
<tr>
&LT;TD height= "colspan=" 2 "><div align=" center ">
<input type= "Submit" value= "release" Name= "HF"/>
</div></td>
</tr>
<tr>
&LT;TD colspan= "2" ><table border= "0" cellpadding= "0" cellspacing= "0" style= "border-collapse:collapse" Bordercolor= "#111111" width= "100%" >
<tr>
&LT;TD width= "100%" height= "1" colspan= "4" ></td>
</tr>
</table></td>
</tr>
</form>
</table>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.