We know that the text box can have an attribute of maxlength, which can limit the length of the text box. At that time, the text box textarea does not exist, so
How can I limit the length of the remarks box? In fact, it is very easy to add such a sentence onkeydown = 'if (this. value. length> = 20) {event. returnvalue = false }'
The entire statement is as follows:
<Textarea name = "A" Cols = "45" rows = "2" onkeydown = 'if (this. value. length> = 20) {event. returnvalue = false} '> AAAA </textarea>
We can also write the judgment in the function. If the input length exceeds the display length, the prompt is displayed as follows:
<HTML>
<Body>
<Form name = "testform">
<Textarea name = "A" Cols = "45" rows = "2"> AAAA </textarea>
<Input type = "button" onclick = "checkvalid ()" value = "Submit">
</Form>
</Body>
</Html>
<Script language = "JavaScript">
Function checkvalid ()
{
VaR A = Document. testform.;
If (A. value. length> 20)
{
Alert ("the length of the input remarks box cannot exceed 20 characters! ");
Return false;
}
Return true;
}
</SCRIPT>
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.