Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textarea count characters validation

i'm writing an asp page using vb.net and i need to count the number of characters in my textarea and display the message:"X characters Remaining."

that's my asp code:

  <td valign='top'>
                <textarea rows="5" id="content_txt" name="TextArea1" runat="server" maxlength="50"></textarea>
            </td>
like image 307
User7291 Avatar asked Mar 23 '23 13:03

User7291


1 Answers

Here is a JSFiddle

HTML:

<textarea rows="5" id="content_txt" name="TextArea1" runat="server" maxlength="50"></textarea>
<p id="message"></p>

JS:

var area = document.getElementById("content_txt");
var message = document.getElementById("message");
var maxLength = 50;
var checkLength = function() {
    if(area.value.length < maxLength) {
        message.innerHTML = (maxLength-area.value.length) + " characters remaining";
    }
}
setInterval(checkLength, 300);
like image 122
Krasimir Avatar answered Apr 01 '23 23:04

Krasimir