<html>
<head>
<style>
.target{
text-align: center;
}
.texttop{
font: bold 12px Arial;
text-align: center;
}
.textleft{
font: bold 11px Arial;
text-align: left;
}
.textright{
font: bold 11px Arial;
text-align: right;
}
.statusbar{
font: bold 11px Arial;
border: 1px solid;
text-align: left;
}
.statustext{
font: bold 11px Arial;
}
</style>
<script>
var strTargetID = "statusbarContainer";
var intStatusWidth = 200;
var strBarColour = "#9999FF";
var strBorderColour = "#666666";
var strTextColour = "#000000";
var strLabel = "Percent Complete";
function statusInit(){
var objTarget = document.getElementById(strTargetID);
objTarget.className = "target";
objTarget.style.color = strTextColour;
var objTextTop = document.createElement("div");
objTextTop.id = "texttop";
objTextTop.className = "texttop";
objTextTop.style.width = intStatusWidth + "px";
objTextTop.innerText = strLabel;
objTarget.appendChild(objTextTop);
var objTextMid = document.createElement("div");
objTextMid.width = intStatusWidth + "px";
var objTextLeft = document.createElement("span");
objTextLeft.id = "textleft";
objTextLeft.className = "textleft";
objTextLeft.innerText = "0%";
objTextLeft.style.width = parseInt(intStatusWidth/2) + "px";
objTextMid.appendChild(objTextLeft);
var objTextRight = document.createElement("span");
objTextRight.id = "textright";
objTextRight.className = "textright";
objTextRight.innerText = "100%";
objTextRight.style.width = parseInt(intStatusWidth/2) + "px";
objTextMid.appendChild(objTextRight);
objTarget.appendChild(objTextMid);
var objStatusBar = document.createElement("div");
objStatusBar.width = intStatusWidth + "px";
objStatusBar.id = "statusbar";
objStatusBar.className = "statusbar";
objStatusBar.style.color = strTextColour;
objStatusBar.style.width = (intStatusWidth + 2) + "px";
objStatusBar.style.borderColor = strBorderColour;
objTarget.appendChild(objStatusBar);
}
function setStatus(value){
try{
var cleanVal = parseInt(value);
if(isNaN(cleanVal)) throw("Incorrect argument type - number expected");
if((cleanVal > 100) || (cleanVal < 0)) throw("Value out of range");
var objStatus = document.getElementById("statusbar");
objStatus.innerHTML = "";
var objStatusLeft = document.createElement("span");
objStatusLeft.style.backgroundColor = strBarColour;
objStatusLeft.style.width = parseInt((cleanVal/100) * intStatusWidth) + "px";
objStatus.appendChild(objStatusLeft);
var objStatusText = document.createElement("span");
objStatusText.className = "statustext";
objStatusText.style.position = "absolute";
objStatusText.style.top = objStatus.offsetTop + "px";
objStatusText.style.left = objStatus.offsetLeft + "px";
objStatusText.style.width = (intStatusWidth + 2) + "px";
objStatusText.style.color = strTextColour;
objStatusText.innerText = cleanVal + "%";
var objTarget = document.getElementById(strTargetID);
objTarget.appendChild(objStatusText);
}
catch(e){
alert(e);
}
}
</script>
</head>
<body onLoad="statusInit();">
<div id="statusbarContainer"></div>
Set status to
<input type="text" id="strPercent" onblur="setStatus(this.value)">%
</body>
</html>