|
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>
|
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.