Skip to content

Ограничение количества вводимой информации в textarea по числу символов средствами JS

<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
 if (limitField.value.length > limitNum) {
  limitField.value = limitField.value.substring(0, limitNum);
 } else {
  limitCount.value = limitNum - limitField.value.length;
 }
}

</script>

<textarea  name="text" id="text" onKeyUp="limitText(this.form.text,this.form.countdown,400);"> </textarea>
<br /><font size="1">(Максимум символов: 400)
<input readonly type="text" name="countdown" size="3" value="100"/> символов осталось.</font>

 

Leave a Reply

Your email address will not be published. Required fields are marked *

π