All this just for a textbox counting entered chars, and working in IE and FF :(
<html>
<body>
<textarea id=tar1></textarea>
Counter: <span id=cnt1>0</span>
<script>
function testf(evt,dest) {
if (window.event) {
if (window.event.srcElement)
dest.innerHTML = (window.event.srcElement.value.length);
}
if (evt) {
if (evt.target)
dest.innerHTML = (evt.target.value.length);
}
}
document.getElementById('tar1').onkeyup=function(evt) {
testf(evt,document.getElementById('cnt1'));
}
</script>
</body>
</html>
2 comments:
<html>
<body>
<textarea onkeypress="Javascript:document.getElementById('cnt1').innerHTML++"></textarea>
Counter: <span id="cnt1">0</span>
</body>
</html>
Hi Bolkin, thx for you mail. The challenge was "textbox counting entered chars, and working in IE and FF", and my code does exactly this, you made no mention that the code should count the number of characters in the textbox, which is a somewhat different challenge ;o) But I accept the new challenge, so here it goes:
<html>
<body>
<textarea id="txt1" onkeyup="Javascript:document.getElementById('cnt1').innerHTML=document.getElementById('txt1').value.length"></textarea>
Counter: <span id="cnt1">0</span>
</body>
</html>
Post a Comment