Display text box can also enter how many words

Source: Internet
Author: User

The code is similar, just a slightly different form of presentation.

The first type, when not entered, hides the

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"
"Http://www.w3.org/TR/html4/loose.dtd" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> Untitled Document </title>
<script language= ' JavaScript ' >
<!--code written by ridincal
var charNum = 0;
function Changeinfo ()
{
CharNum = Document.all.ipt.value.length;
var maxLength = document.all.ipt.maxLength;
if (maxlength>=charnum) document.all.info.innerhtml= "Send up to 20 words, remaining" + (20-charnum) + "word. ";
}
-->
</script>

<body>
<input type= "text" id= "IPT" onkeyup= "Changeinfo ()" Maxlength= "><span id=" info "> send up to 20 words </span>
</body>

The second type shows the remaining words directly

<meta charset= "gb2312"
<script language= "JavaScript"
MaxLen = 100;
function Checkmaxinput (form) { 
if (Form.message.value.length > MaxLen) {
Form.message.value = Form.message.value.substring (0, MaxLen);
} else {
Form.remLen.value = maxlen-form.message.value.length;
}

</script>
<body>
<form name=myform>
<font size= "2" Color= "Red" > (you can enter up to 100 characters) </font><br>
<textarea name=message wrap=physical cols=28 Onkeydown= "Checkmaxinput (this.form)" ></textarea>
<br>
<font size= "2" > can also enter words: </ Font>
<input type=text name=remlen size=2 maxlength=3 value=;
Readonly>
</form> Body>

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.