Code: Select all
onKeyDown="textCounter(this,'progressbar1',500)"
onKeyUp="textCounter(this,'progressbar1',500)"
onFocus="textCounter(this,'progressbar1',500)"></textarea><br />
<div id="progressbar1" class="progress" style="position:absolute;left:15px;top:530px"></div>
<script>textCounter(document.getElementById("TextArea1"),"progressbar1",500)</script
And change the ("TextArea1") to what you need.
And chane left:15px;top:530px to what you need.
Put this code in an html box (<head></head>tags)
Code: Select all
<style type="text/css">
.progress{
width: 1px;
height: 14px;
color: white;
font-size: 12px;
overflow: hidden;
background-color: #FF0000;
padding-left: 5px;
}
</style>
<script type="text/JavaScript">
function textCounter(field,counter,maxlimit,linecounter) {
// text width//
var fieldWidth = parseInt(field.offsetWidth);
var charcnt = field.value.length;
// trim the extra text
if (charcnt > maxlimit) {
field.value = field.value.substring(0, maxlimit);
}
else {
// progress bar percentage
var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
document.getElementById(counter).style.width = parseInt((fieldWidth*percentage)/101)+"px";
document.getElementById(counter).innerHTML=" "+percentage+"%"
// color correction on style from CCFFF -> CC0000
setcolor(document.getElementById(counter),percentage,"background-color");
}
}
function setcolor(obj,percentage,prop){
obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
</script>
http://test3.fcab.se/members/test/maxcharacters.html