...

View Full Version : Text box limiter with remaining characters



mw2005
08-14-2005, 05:37 PM
How can I limit a text box to 50 characters and display the amount of characters left?

Any help will be appreciated;
Thanks,
MW2005

Kor
08-15-2005, 10:24 AM
try this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var maxL=50;//nr of max permited characters
function limit(obj){
var nr= document.getElementById('nrc')
var v = new String();
s = obj.value.split('');
for(i=0;i<maxL;i++){v += s[i]}
if(s.length>=maxL){
obj.value=v;
nr.firstChild.data = maxL-v.length;
}
else{nr.firstChild.data = maxL-s.length;}
}
onload=function(){
document.getElementById('nrc').firstChild.data=maxL;
}
</script>
</head>
<body>
<input type="text" onkeyup="limit(this)"><span id="nrc">&nbsp;</span>&nbsp;characters left
</body>
</html>

mw2005
08-15-2005, 04:13 PM
Thanks :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum