Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Form | Q1539 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.