I tried to make a new textarea with a progressbar under it that colors red when it fills to a maximum character input maybe something for this forums inputbox.
If someone has extra idea's to make it better for crossbrowser use please reply:
here is the code
<script language="JavaScript" type="text/JavaScript">
function textCounter(field,counter,maxlimit,linecounter) {
// text width//
var fieldWidth = parseInt(field.style.width);
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)/100)+"px"; // color correction on style from CCFFF -> CC0000
setcolor(document.getElementById(counter),percentage,"background-color");
}
}
This is a version that keeps the coloring bar under the text area, but i still can't get the textarea vertical top aligned on IE mac, do i have to use a different stylesheet property for ie to align the textbox on text top in IE? For safari the only style that worked for me was inline-table (inline didn't work).
Code:
<script language="JavaScript" type="text/JavaScript">
function textCounter(field,counter,maxlimit) {
// total text count
var fieldWidth = parseInt(field.style.width);
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)/100)+"px";
// color correction on style from CCFFF -> CC0000 use background for ie, background-color for safari
col= (typeof document.all)? "background":"background-color";
setcolor(document.getElementById(counter),percentage,col);
}
}
function setcolor(obj,percentage,prop){
obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
</script>
<style type="text/css">
<!--
.progress {
width: 1px;
height: 4px;
background-color:#CCFFFF;
font-size: 4px;
}
.inlinediv {
display:inline-table;
position: relative;
width: 200px;
vertical-align:text-top;
}
-->
</style>
<form>
Fieldtext label
<div id="limitDiv" class="inlinediv">
<textarea name="limiter" cols="" rows="5" id="limiter" style="width:200px" title="enter maximum 200 characters" onFocus="textCounter(this,'limiter_pr',200)" onKeyDown="textCounter(this,'limiter_pr',200)" onKeyUp="textCounter(this,'limiter_pr',200)"></textarea><br />
<div id="limiter_pr" class="progress" > </div></div>
</form>
<script>textCounter(document.getElementById("limiter"),"limiter_pr",200)</script>
Bookmarks