Greetings
I have written an online survey with 110 questions. I use javascript to cycle
thru all the questions which are displayed in an iframe.
I keep track of the question number using a "global" variable.
When testing it, everything works fine until I hit the back button. The iframe
goes to the previous question, but of course, the counter is not decremented.
Example if I am at question # 5 and I hit the back button, I go to #4, but If I
proceed to the next question, the count jumps to #6 rather than 4.
I did this using cookies once- each question represented a new page generated
by Python. This handled the back button problem just fine,
I like the fact that Iframes greatly reduce my bandwidth usage.
Any Ideas or do you need more details.
Below is the Javascript I used. Simple I know. I am learning.
//
<script language="JavaS cript">
var response=new Array(111);
var scores =new Array(23);
var rank =new Array(23);
var toprank=new Array(23);
var num=0;
var numtoprank=0;
var list=new Array(23);
var Rnum=new Array(23);
function zeronum()
{
num=0;
}
function rankresponse()
{
var temp=0;
for (n=0;n<22;n++)
{
rank[n]=0;
list[n]=n;
}
for (n=0; n<22;n++)
rank[n] = response[n] + response[n+22] + response[n+44] + response[n+66]
+ response[n+88];
for (n=0; n<22;n++)
{
Rnum[n] = rank[n];
for (j=n+1; j<22;j++)
{
if(rank[j]>Rnum[n])
{
Rnum[n] = rank[j];
rank[j]=rank[n]
rank[n]=temp;
temp=list[j];
list[j]=list[n];
list[n]=temp;
}//end if
} //end for j
}//end for n
}
function aa(start)
{
var s="http://mywebsiteactual urlhere.com/testresults.php 4?";
if (num<=108){
num=num+1;
response[num-1]=start;
window.frames.a nIframe.locatio n.href
='statements/statement'+num. toString()+'.ht m';
}
else {
rankresponse();
//window.frames.a nIframe.locatio n.href
='giftresults/results'+topran k.toString()+'. htm';
// document.write( "<hr><h1>TH e program chose, "
+list[1]+"@"+list[2]+list[3]+"</h1><hr>");
s=s+'g1='+list[0].toString()+'&g 2='+list[1].toString()+'&g 3='+list[2].toSt
ring();
document.locati on=s;
}
}
</script>
Allen
I have written an online survey with 110 questions. I use javascript to cycle
thru all the questions which are displayed in an iframe.
I keep track of the question number using a "global" variable.
When testing it, everything works fine until I hit the back button. The iframe
goes to the previous question, but of course, the counter is not decremented.
Example if I am at question # 5 and I hit the back button, I go to #4, but If I
proceed to the next question, the count jumps to #6 rather than 4.
I did this using cookies once- each question represented a new page generated
by Python. This handled the back button problem just fine,
I like the fact that Iframes greatly reduce my bandwidth usage.
Any Ideas or do you need more details.
Below is the Javascript I used. Simple I know. I am learning.
//
<script language="JavaS cript">
var response=new Array(111);
var scores =new Array(23);
var rank =new Array(23);
var toprank=new Array(23);
var num=0;
var numtoprank=0;
var list=new Array(23);
var Rnum=new Array(23);
function zeronum()
{
num=0;
}
function rankresponse()
{
var temp=0;
for (n=0;n<22;n++)
{
rank[n]=0;
list[n]=n;
}
for (n=0; n<22;n++)
rank[n] = response[n] + response[n+22] + response[n+44] + response[n+66]
+ response[n+88];
for (n=0; n<22;n++)
{
Rnum[n] = rank[n];
for (j=n+1; j<22;j++)
{
if(rank[j]>Rnum[n])
{
Rnum[n] = rank[j];
rank[j]=rank[n]
rank[n]=temp;
temp=list[j];
list[j]=list[n];
list[n]=temp;
}//end if
} //end for j
}//end for n
}
function aa(start)
{
var s="http://mywebsiteactual urlhere.com/testresults.php 4?";
if (num<=108){
num=num+1;
response[num-1]=start;
window.frames.a nIframe.locatio n.href
='statements/statement'+num. toString()+'.ht m';
}
else {
rankresponse();
//window.frames.a nIframe.locatio n.href
='giftresults/results'+topran k.toString()+'. htm';
// document.write( "<hr><h1>TH e program chose, "
+list[1]+"@"+list[2]+list[3]+"</h1><hr>");
s=s+'g1='+list[0].toString()+'&g 2='+list[1].toString()+'&g 3='+list[2].toSt
ring();
document.locati on=s;
}
}
</script>
Allen
Comment