Err... what's wrong with:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>max length</title>
<script type="text/javascript">
function loadMax(el,max) {
var end = document.createElement("div");
el.load = function() {
var charc = max-el.value.length,str=document.createTextNode("There are "+charc+" characters remaining.");
while (f=end.firstChild) end.removeChild(f);
end.appendChild(str);
}
el.load();
el.parentNode.appendChild(end);
el.onkeydown = function() {
el.value=el.value.substring(0,max);
el.load();
}
}
</script>
</head>
<body>
<form name="myForm">
<input type="text" name="foo">
</form>
<script type="text/javascript">
loadMax(document.forms['myForm'].foo,10);
</script>
</body>
</html>
//EDIT: created a work-around for the weird positioning:
Code:
<form name="myForm">
<div>
<input type="text" name="foo">
</div>
<div>
<textarea name="test"></textarea>
</div>
</form>
Bookmarks