Reputation: 158
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!
Upvotes: 0
Views: 588
Reputation: 1
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>
Upvotes: 0
Reputation: 784
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
});
Upvotes: 2
Reputation: 7595
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>
Upvotes: 1