Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1539 How can I have a realtime character counter for a textarea?

You are here: irt.org | FAQ | JavaScript | Form | Q1539 [ previous next ]

Try:

<body onLoad="document.myForm.smsInput.focus()">

<form NAME="myForm">

<input type="text" name="count" value="160" size="3" onFocus="this.blur" readonly>

<br>

<textarea rows="5" cols="50" name="smsInput" wrap
onKeyUp="
val = this.value;
if (val.length > 160) {
  alert('Sorry, you are over the limit of 160 characters');
  this.value = val.substring(0,160);
  smsInput.focus()
}
this.form.count.value=160-parseInt(this.value.length);
"></textarea>

</form>

</body>

©2018 Martin Webb