rgb192
asked on
character count as I am typing into an input textbox
character count as I am typing into an input textbox
Something along these lines (untested, sorry):
<script type="text/javascript">
function io_count(src, tgt) {
if (src.nodeName && src.nodeName === "INPUT") {
if (typeof tgt === "string") {
tgt = document.getElementById(tgt);
}
tgt.value = src.length;
return false;
}
return true;
}
</script>
...
<body>
<input id="txt_test1" onchange="return io_count(this, 'div_test1');" value="" />
<div id="div_test1"></div>
<input id="txt_test2" onchange="return io_count(this, 'div_test2');" value="" />
<div id="div_test2"></div>
...
</body>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, I forgot a little trick. Add this function within <script> tags:
function emptyText(){
document.getElementById('t esttext'). value = '';
}
and add this to the <body tag:
<body onload="emptyText();">
This ensure that refreshing the page the text box is empty and the count begin from 0.
Bye
function emptyText(){
document.getElementById('t
}
and add this to the <body tag:
<body onload="emptyText();">
This ensure that refreshing the page the text box is empty and the count begin from 0.
Bye
or
window.onload=function() {
countChars();
}
window.onload=function() {
countChars();
}
Still need you assistance with this?
ASKER
thanks
http://www.dotnetspider.com/forum/221235-In-javascript-how-count-textbox-letteres-inputbox-while-typing-characteres-if-le.aspx