html head script language javascript type text javascript function cha

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<html>
<head>
<script language="javascript" type="text/javascript">
function changeCounter(value1,value2){
counter = document.getElementById('cremain');
counter.innerHTML = value1 - value2;
}
function maxlengthNormal(obj, mlength){
if (obj.value.length>mlength){
obj.value=obj.value.substring(0,mlength)
changeCounter(0,0);
}
else{
changeCounter(mlength,obj.value.length);
}
}
function maxlengthPaste(obj,mlength){
if(window.clipboardData.getData("Text").length > mlength){
obj.value=window.clipboardData.getData("Text").value.substring(0,mlength)
changeCounter(0,0);
}
else{
changeCounter(mlength,obj.value.length);
}
}
</script>
</head>
<body>
<form>
<textarea cols="40" rows="3" onkeyup="return maxlengthNormal(this,160)" onpaste="return maxlengthPaste(this,160)"></textarea>
<p id="cremain">160</p>
</form>
</body>
</html>