Ramesh
Ramesh

Reputation: 163

How to limit character in jquery tags input?

i have used the following code to limit the character but it is not working.. pls help me. thanks in advance.

 <td nowrap="nowrap">
     <asp:TextBox MaxLength="60" runat="server" ID="Keyword" CssClass="TaskTitle" Width="270px"
                            TextMode="SingleLine" />
 </td>

$('#Keyword_tag').bind('keyup', function() {

    var characterLimit = 60;
    var charactersUsed = $('#Keyword').val();

    charactersUsed = charactersUsed.replaceAll(',');
           if (charactersUsed.length > characterLimit) {
    alert(charactersUsed.length);
        charactersUsed.length = characterLimit;
        alert(charactersUsed.length);
        $(this).val($(this).val().slice(0, characterLimit));
        $(this).scrollTop($(this)[0].scrollHeight);
    }

I have to limit the character to 60 but when i assign the character limit value to character used it is not getting assigned. I am using jquery tags input plugin for the keyword field

Upvotes: 0

Views: 1224

Answers (1)

alex
alex

Reputation: 490323

I have to limit the character to 60...

Here's a solution...

$('#Keyword_tag').on('keyup paste', function() {
    $(this).val(function(i, value) { return value.substr(0, 60); });
});

Upvotes: 3

Related Questions