[FONT=Tahoma]Can you help? I’ve been searching the forum for a progress bar that tells you how much of a form has been completed by a user as they answer questions.
You probably all seen the or filled out the forms where you answer a few questions, then click a button to continue on to some more questions and a small percentage indicator appears at the top, telling you how far you’re into the form.
I have a form that does exactly this, you answer 10 questions, click next, and then another 10 questions appear and so on….
(The form uses a javascipt function where all the form is hidden initially and as the user clicks to start or presses next, certain parts of it as shown and others hidden etc.)
Can anyone provide a script that calculates the percentage complete and shows it as a small vertical bar?
You’ll be a life saver if you can!! ? [/FONT]
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var bgF ='#FF0000';
var bgL ='#FFFFFF';
function progB(){
var outH=document.getElementById('barout').offsetHeight;
var aInp = document.getElementsByTagName('input');
var aTxt = [];
for(var i=aInp.length-1;i>=0;i--){
if(aInp[i].type=='text'){aTxt[aTxt.length]=aInp[i]}
}
var txL=aTxt.length; var txF=0;
for(var i=aTxt.length-1;i>=0;i--){
if(aTxt[i].value.length>0){txF++}
}
var inH=Math.floor(outH*(txF/txL));
var pBar=document.getElementById('barin');
pBar.style.height=inH+'px';
pBar.style.backgroundColor=(txF==0)?bgL:bgF;
}
</script>
<style type="text/css">
<!--
#barout {
border: 1px solid #FF0000;
height: 140px;
width: 20px;
}
#barin {
width: 100%;
}
-->
</style>
</head>
<body>
<form>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20" rowspan="7" valign="top"><div id="barout">
<div id="barin"> </div>
</div></td>
<td bgcolor="#f5f5f5">
<input type="text" onkeyup="progB()"></td>
</tr>
<tr>
<td bgcolor="#f5f5f5">
<input type="text" onkeyup="progB()"></td>
</tr>
<tr>
<td bgcolor="#f5f5f5">
<input type="text" onkeyup="progB()"></td>
</tr>
<tr>
<td bgcolor="#f5f5f5">
<input type="text" onkeyup="progB()"></td>
</tr>
<tr>
<td bgcolor="#f5f5f5">
<input type="text" onkeyup="progB()"></td>
</tr>
<tr>
<td bgcolor="#f5f5f5">
<input type="text" onkeyup="progB()"></td>
</tr>
<tr>
<td bgcolor="#f5f5f5">
<input type="text" onkeyup="progB()"></td>
</tr>
</table>
</form>
</body>
</html>
[/code]
<i>
</i><html>
<head>
<title>Progress Bar Example</title>
<style type="text/css">
#progressDiv { width:400px;height:50px;background:#ccc;color:#333;font-family:sans-serif;font-size:20px;font-weight:bold;position:relative;top:0;left:0; }
#progressDivText { margin-top:15px;position:absolute;left:0;height:100%;text-align:center; }
#progressBar { width:0%;height:100%;background:#333;color:#ccc;text-align:center;overflow:hidden;position:relative;left:0; }
#progressBarText { margin-top:15px;position:absolute;left:0;height:100%;text-align:center; }
</style>
<script type="text/javascript">
function setProgress(percent)
{
percent = Math.max(0, Math.min(100, Number(percent)));
<i> </i>percent = percent.toFixed(1);
<i> </i>var progressBar = document.getElementById("progressBar");
<i> </i>var text = percent + "% Complete";
<i> </i>progressBar.style.width = percent + "%";
<i> </i>setProgressText("progressBarText", text);
<i> </i>setProgressText("progressDivText", text);
}
function setProgressText(id, text)
{
var div = document.getElementById(id);
<i> </i>if (!div.style.width)
<i> </i> div.style.width = document.getElementById("progressDiv").offsetWidth + "px";
<i> </i>var textNode = document.createTextNode(text);
<i> </i>if (div.firstChild)
<i> </i> div.replaceChild(textNode, div.firstChild);
<i> </i>else
<i> </i> div.appendChild(textNode);
}
var p = 0;
function demo()
{
p += 0.1;
<i> </i>if (p > 100)
<i> </i> p = 0;
<i> </i>setProgress(p);
}
setInterval('demo()', 100);
</script>
</head>
<body>
<div id="progressDiv"><div id="progressDivText"></div><div id="progressBar"><div id="progressBarText"></div></div></div>
</body>
</html>
<i>
</i>#progressDiv { width:400px;height:50px;background:#ccc;color:#333;font-family:sans-serif;font-size:20px;font-weight:bold;position:relative;top:0;left:0; }
#progressDivText { margin-top:15px;position:absolute;left:0;height:100%;text-align:center; }
#progressBar { width:0%;height:100%;background:#333;color:#ccc;text-align:center;overflow:hidden;position:relative;left:0; }
#progressBarText { margin-top:15px;position:absolute;left:0;height:100%;text-align:center; }
[CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Demo form</title>
<script>
/***********************************************
* Multi-Part Content script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
if (document.getElementById){
document.write('<style type="text/css">')
document.write('.multiparts, #formnavigation{display:none;}')
document.write('</style>')
}
var curpart=0
function getElementbyClass(classname){
partscollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
partscollect[inc++]=alltags[i]
}
}
function cycleforward(){
partscollect[curpart].style.display="none"
curpart=(curpart<partscollect.length-1)? curpart+1 : 0
partscollect[curpart].style.display="block"
updatenav()
self.scrollTo(0, 330)
}
function cycleback(){
partscollect[curpart].style.display="none"
curpart=(curpart>0)? curpart-1 : partscollect.length-1
partscollect[curpart].style.display="block"
updatenav()
self.scrollTo(0, 330)
}
function updatenav(){
document.getElementById("backbutton").style.visibility=(curpart==0)? "hidden" : "visible"
document.getElementById("forwardbutton").style.visibility=(curpart==partscollect.length-1)? "hidden" : "visible"
}
function onloadfunct(){
getElementbyClass("multiparts")
partscollect[0].style.display="block"
document.getElementById("formnavigation").style.display="block"
updatenav()
}
if (window.addEventListener)
window.addEventListener("load", onloadfunct, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunct)
else if (document.getElementById)
window.onload=onloadfunct
</script>
</head>
<body>
<form action="barometerSubmit.asp" method="post" name="barometerForm" id="barometerForm" onSubmit="return validateForm(this);">
<div class="multiparts" style="display: block">
<table width="95%" border="0" cellpadding="0" cellspacing="0" class="formtable">
<tr>
<td class="label">(1) How many issues of In Focus do you receive?</td>
</tr>
<tr>
<td class="options">
<ul class="radio">
<li><input type="radio" name="q01" value="all">all</li>
<li><input type="radio" name="q01" value="most">most</li>
<li><input type="radio" name="q01" value="some">some</li>
<li><input type="radio" name="q01" value="none">none</li>
</ul>
</td>
</tr>
<tr>
<td class="label">(2) How much of each issue do you read?</td>
</tr>
<tr>
<td class="options">
<ul class="radio">
<li><input type="radio" name="q02" value="all">all</li>
<li><input type="radio" name="q02" value="most">most</li>
<li><input type="radio" name="q02" value="some">some</li>
<li><input type="radio" name="q02" value="none">none</li>
</ul>
</td>
</tr>
</table>
</div>
<div class="multiparts">
<table width="95%" border="0" cellpadding="0" cellspacing="0" class="formtable">
<tr>
<td class="label">(3) How well written do you find the articles?</td>
</tr>
<tr>
<td class="options">
<ul class="radio">
<li><input type="radio" name="q03" value="very well">very well</li>
<li><input type="radio" name="q03" value="well">well</li>
<li><input type="radio" name="q03" value="fairly well">fairly well</li>
<li><input type="radio" name="q03" value="not very well">not very well</li>
</ul>
</td>
</tr>
<tr>
<td class="label">(4) How well designed do you find the publication?</td>
</tr>
<tr>
<td class="options">
<ul class="radio">
<li><input type="radio" name="q04" value="very well">very well</li>
<li><input type="radio" name="q04" value="well">well</li>
<li><input type="radio" name="q04" value="fairly well">fairly well</li>
<li><input type="radio" name="q04" value="not very well">not very well</li>
</ul>
</td>
</tr>
</table>
</div>
<div class="multiparts">
<table width="95%" border="0" cellpadding="0" cellspacing="0" class="formtable">
<tr>
<td class="label">(5) How well do you find the publication keeps you informed?</td>
</tr>
<tr>
<td class="options">
<ul class="radio">
<li><input type="radio" name="q05" value="very well">very well</li>
<li><input type="radio" name="q05" value="well">well</li>
<li><input type="radio" name="q05" value="fairly well">fairly well</li>
<li><input type="radio" name="q05" value="not very well">not very well</li>
</ul>
</td>
</tr>
<tr>
<td class="label">(6) Some initial feedback has suggested that there should be an increased focus on supervision topics. Do you agree?</td>
</tr>
<tr>
<td class="options">
<ul class="radio">
<li><input type="radio" name="q06" value="yes">yes</li>
<li><input type="radio" name="q06" value="no">no</li>
<li><input type="radio" name="q06" value="don't mind">don't mind</li>
</ul>
</td>
</tr>
<tr>
<td class="label">(7) The style and content of In Focus was heavily revised at the end of 2004. Is it an improvement?</td>
</tr>
</table>
</div>
<div class="multiparts">
<table width="95%" border="0" cellpadding="0" cellspacing="0" class="formtable">
<tr>
<td class="options">
<ul class="radio">
<li><input type="radio" name="q07" value="yes very">yes very</li>
<li><input type="radio" name="q07" value="yes fairly">yes fairly</li>
<li><input type="radio" name="q07" value="not much">not much</li>
<li><input type="radio" name="q07" value="no">no</li>
<li><input type="radio" name="q07" value="not in RMBU prior to 2005">not in RMBU prior to 2005</li>
</ul>
</td>
</tr>
<tr>
<td class="label">(8) Overall how well do you find In Focus does as a staff magazine?</td>
</tr>
<tr>
<td class="options">
<ul class="radio">
<li><input type="radio" name="q08" value="very well">very well</li>
<li><input type="radio" name="q08" value="well">well</li>
<li><input type="radio" name="q08" value="fairly well">fairly well</li>
<li><input type="radio" name="q08" value="not very well">not very well</li>
</ul>
</td>
</tr>
</table>
<input type="submit" value="Submit" class="submit" alt="Submit your answers">
</div>
<div id="formnavigation" style="width:200px; display:none;margin-top:10px;">
<a id="backbutton" href="javascript:cycleback()" style="float:left;cursor:hand;">Previous</a>
<a id="forwardbutton" href="javascript:cycleforward()" style="float:right;cursor:hand;">Continue</a>
</div>
</body>
</html>[/CODE]
<i>
</i>var p = 0;
function demo()
{
p += 0.1;
<i> </i>if (p > 100)
<i> </i> p = 0;
<i> </i>setProgress(p);
}
setInterval('demo()', 100);
<i>
</i>setProgress(33.3);
<table width=100% border=1><tr><td valign=top><table width=100% border=0>
<td valign=top id=1 class=first> </td>
<td valign=top id=2 class=2> </td>
<td valign=top id=3 class=3> </td>
</table></td></tr></table>
0.1.9 — BETA 4.28