0

I want to use this nice little code: http://mimo84.github.io/bootstrap-maxlength/. I'm really new to asp.net programming and I don't know how to use this in my project. My Textboxes are already created and the MaxLength attribute is set to my desired value. Can someone tell me why it's not working.

<asp:TextBox ID="TextBox1" runat="server" MaxLength="20" onfocus="show()"></asp:TextBox> <script type="text\javascript"> function show(){ $('input[TextBox1]').maxlength(); } </script> 

The needed javascript files are referenced in the master file!

3
  • 1
    The github page literally explains how to implement the plugin Commented Dec 21, 2015 at 17:17
  • For me its not clear at all =(. I linked the needed files for sure but now I really don't know how. Please help me if you know how. Commented Dec 21, 2015 at 17:19
  • $("#textBoxID").maxlength(); Commented Dec 21, 2015 at 17:22

3 Answers 3

2

ref the maxlength.js file

<script src="../bootstrap-maxlength/bootstrap-maxlength.min.js"></script> <input type="text" class="form-control" maxlength="25" name="alloptions" id="alloptions"> $('input.className').maxlength({ alwaysShow: true, threshold: 10, warningClass: "label label-success", limitReachedClass: "label label-danger", separator: ' of ', preText: 'You have ', postText: ' chars remaining.', validate: true }); 

See Demo Here

Sign up to request clarification or add additional context in comments.

Comments

1

Assuming you have jQuery and the maxlength plugin referenced all you need to do is add script to your page as follows:

<script type="text\javascript">$('input[YOUR_FIELD_ID]').maxlength();</script> 

5 Comments

Thank you, but my question is where I have to add this line? Ty
within a script block (preferably after the body element). I have edited the answer.
after hours of testing I still can't find the answer. Is it possible that it just does not work in asp? I think the problem is that the javascript function will never be called. How can I test this?
Show what you got so far. Help us help you :)
I have edited my question. There is the code which I already have
0

Remove MaxLength attribute from TextBox control And Define MaxLength in javascitp function like below:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <script type="text/javascript"> $(document).ready(function () { $("[id*=TextBox1]").maxlength({ alwaysShow: true, validate: true, allowOverMax: false, customMaxAttribute: "100" }); }); </script> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.