Hi, I have a piece of javascript code which works with Coldfusion to produce a 'progress meter' which shows graphically how many far someone has progressed through a rather long form.
Basically the code is executed everytime a person moves from one question to the next (using the onBlur attribute). It replaces a white.gif image with a blue.gif image and gives the appearance of a progress bar.
It works fine as long as the user moves from question 1 to question 2 ect in a sequential manner (I have only shown code for the 1st question). The problem is the user might ignore question 1 and answer question 3. In this case document.Block3.src would be set to "../images/blue.gif"; and the 3rd progress bar (but not 1 or 2) is shown as blue. This looks weird and is not how conventional progress bars work.
What I need is a more dynamic solution which will set document.Block1.src to "../images/blue.gif"; WHICHEVER question is selected. I had a go below but I can't get it to work - I know you clever javascript people will probably laugh at how easy it is to get the syntax right!
Thanks
Steve
Basically the code is executed everytime a person moves from one question to the next (using the onBlur attribute). It replaces a white.gif image with a blue.gif image and gives the appearance of a progress bar.
It works fine as long as the user moves from question 1 to question 2 ect in a sequential manner (I have only shown code for the 1st question). The problem is the user might ignore question 1 and answer question 3. In this case document.Block3.src would be set to "../images/blue.gif"; and the 3rd progress bar (but not 1 or 2) is shown as blue. This looks weird and is not how conventional progress bars work.
What I need is a more dynamic solution which will set document.Block1.src to "../images/blue.gif"; WHICHEVER question is selected. I had a go below but I can't get it to work - I know you clever javascript people will probably laugh at how easy it is to get the syntax right!
Thanks
Steve
Code:
// Static code looks weird
function progress(f) {
var feedbackform = document.forms['feedbackform'];
var aaq1_have_you_used_about_you = "";
for (i=0; i<feedbackform.aaq1_have_you_used_about_you.length; i++) {
if (feedbackform.aaq1_have_you_used_about_you[i].checked) {
document.Block1.src = "../images/blue.gif";
}
}
<!--- Coldfusion Code to show progress meter --->
<CFOUTPUT><TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0><TR><TD><TABLE WIDTH="100" CELLPADDING=0 CELLSPACING=0 BORDER=0><TR><TD>Progress: </TD></CFOUTPUT>
<CFLOOP INDEX="X" FROM=1 TO=10>
<CFOUTPUT>
<TD><IMG SRC="images/white.gif" NAME="Block#X#" WIDTH=10 HEIGHT=15 ALT="Progress Bar"></TD>
</CFOUTPUT>
</CFLOOP>
<CFOUTPUT></TR></TABLE></TD></TR></TABLE><P></CFOUTPUT>
<CFFLUSH>
//My attempt at dynamic code
function progress(f) {
var feedbackform = document.forms['feedbackform'];
var aaq1_have_you_used_about_you = "";
var bbq1_now_have_clearer_understanding_of_own_experience = "";
var BlockNumber = 0;
for (i=0; i<feedbackform.aaq1_have_you_used_about_you.length; i++) {
if (feedbackform.aaq1_have_you_used_about_you[i].checked) {
BlockNumber = BlockNumber +1; //try to increment BlockNumber so that whichever question is attempted the progress meter always increments in sequence
document.Block+BlockNumber.src = "../images/blue.gif" // display next blue block in progress bar;
}
}