Js listens for mouse events to control the number of input strings in the textarea

  • 2020-03-30 04:03:07
  • OfStack

【 Html code 】


<table>

<tr>

<td width="150"> Text message content: </td>

<td>

<textarea name="message" cols="96" rows="5" onKeyDown="textCounter(message,remLen,65);"

onKeyUp="textCounter(message,remLen,65);"></textarea>

<td>
</tr>

<tr><td></td>
<td> You can also type :<input name="remLen" type="text" value="65" size="5" readonly="readonly"> A character , Maximum allowed per SMS <strong>65</strong> A character </td>

</tr>

</table>

[corresponding js code]


<script>
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}
</script>

Related articles: