This article describes the method of countdown of text input in JavaScript text box. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows: <html>
<head>
<title>Enter text countdown effect in text box</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
maxLen = 100; //Define the maximum number of words that the user can enter
function checkMaxInput(obj) {
if (obj.value.length > maxLen){ //If the number of words entered exceeds the limit
obj.value = obj.value.substring(0, maxLen); // Just remove the extra words
remLen.innerText = 'What you entered exceeds the word limit'
}
else{
remLen.innerText = 'Left' + (maxLen - obj.value.length) + 'word';//Calculate and display the remaining words
}
}
// End -->
</script>
</head>
<body>
<table cellpacing="0" cellpadding="0" bordercolorlight="#000000" bgcolor="#808080">
<tr>
<td><b><font color=ffffffff>Countdown text box</font></b></td>
</tr>
<tr>
<td>
<form name=tickform>
<p align="center">
<textarea name=msgbox rows=5 cols=31 onKeyDown="checkMaxInput(this)" onKeyUp="checkMaxInput(this)" style="background-color: #000000; color: #FFFFF;overflow:auto"></textarea>
</p>
</td>
</tr>
</form>
<tr>
<td>
<font align="right" id=remLen><b></b></font>
</td>
</tr>
</table>
</body>
</html>
I hope this article will be helpful to everyone's JavaScript programming.