admin管理员组文章数量:1410731
i have a textbox and i want dynamic character count of how many char are left out of total max limit=500.
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" Width="300" Height="100">asp:TextBox>
i have a textbox and i want dynamic character count of how many char are left out of total max limit=500.
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" Width="300" Height="100">asp:TextBox>
Share
Improve this question
asked Jun 12, 2017 at 7:21
user8080469user8080469
0
2 Answers
Reset to default 4You can use val.value.length
to get a number of characters in the textbox/textarea.
function countChar(val) {
var len = val.value.length;
if (len >= 500) {
val.value = val.value.substring(0, 500);
} else {
$('.numbersofChart').text(500 - len);
}
};
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="TextBox2" onkeyup="countChar(this)"></textarea>
<div class="numbersofChart"></div>
solved your issue please test this code may help you better
<h5 >Characters Left <span id="remaining">500</span></h5>
<input type="text" id="question_ment_body" name="question_ment_body" placeholder="Your Comment Here...">
<script type="text/javascript">
function charCount() {
var textEntered = document.getElementById('question_ment_body').value;
var msg = document.getElementById('remaining');
var counter = (500-(textEntered.length));
msg.textContent = counter;
}
var el = document.getElementById('question_ment_body');
el.addEventListener('keyup',charCount,false);
</script>
本文标签: javascriptDynamic character count of aspnet text box using JSJqueryStack Overflow
版权声明:本文标题:javascript - Dynamic character count of asp.net text box using JSJquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744942122a2633552.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论