Frame navigation

R

rgarimella

Hi Folks

I have a back and next function. Back takes to the previous page and
Next takes to the next page. On some pages I want users to answer a
question before hitting the next button. If the users do not answer the
question the next displays an alert box. Now the following code does
that. But here is the PROBLEM

If you have answered the question once and you go back. You NEED NOT
answer the question again and clicking NEXT function will take you to
the next page

Each content page has a variable. The following goes on each top
content page
<script language="javascript">
var pageNext = "ab_04_01_0030" ;
var pageBack = "ab_04_01_0010" ;
eval("var " + pageBack + "answered = false"); // dynamic variable
set per page
</SCRIPT>


// The following functions are in another frame called navigation
function GoNext(page_name)
{
page_name = page_name + ".htm" ;
if (page_name != "#"){
var valu = top.Content.pageBack ; // Frame name is content
if (top.Content.eval(valu+ "answered") == true) {
top.Content.location.href = page_name;
}else{
alert("You need to answer the question");
CheckAnswer();
}
}
}

function CheckAnswer (){
var valu = top.Content.pageBack ;
top.Content.eval(valu+ "answered = true") ;
// temporarily sets that you have answer the question
}
 
R

Randy Webb

(e-mail address removed) said the following on 5/18/2006 10:53 AM:
Hi Folks

I have a back and next function. Back takes to the previous page and
Next takes to the next page. On some pages I want users to answer a
question before hitting the next button. If the users do not answer the
question the next displays an alert box. Now the following code does
that. But here is the PROBLEM

Your code has more problems than that.
If you have answered the question once and you go back. You NEED NOT
answer the question again and clicking NEXT function will take you to
the next page

Set a cookie.
Each content page has a variable. The following goes on each top
content page
<script language="javascript">

<script type="text/javascript">

But irrelevant to your question.
var pageNext = "ab_04_01_0030" ;
var pageBack = "ab_04_01_0010" ;
eval("var " + pageBack + "answered = false"); // dynamic variable
set per page

window[pageBack + 'answered'] = false;
//look Ma! No eval

But irrelevant to your question.

Or, if you are creating the pageNext and pageBack on the server (or hard
coded even), then simply add one more line of code:

var ab_04_01_0010answered = false;
</SCRIPT>


// The following functions are in another frame called navigation
function GoNext(page_name)
{
page_name = page_name + ".htm" ;
if (page_name != "#"){
var valu = top.Content.pageBack ; // Frame name is content
if (top.Content.eval(valu+ "answered") == true) {

if (top.Content[valu+'answered'] == true)
top.Content.location.href = page_name;
}else{
alert("You need to answer the question");
CheckAnswer();
}
}
}

function CheckAnswer (){
var valu = top.Content.pageBack ;
top.Content.eval(valu+ "answered = true") ;

top.Content[valu+'answered'] == true;
// temporarily sets that you have answer the question
}

Set a cookie for each page. Check that cookie. But then you will run
into an onload not firing on a Back button. The simplest way around that
is to add a unique string to the URL so that the page gets loaded from
the server.

'somePage.html?'+ new Date().getTime();

Read the Cookie, if the question has already been answered, then act
accordingly. Or, keep track of answers in the Frameset itself (which
seems like the best way anyway)
 
R

Randy Webb

Evertjan. said the following on 5/18/2006 3:57 PM:
Randy Webb wrote on 18 mei 2006 in comp.lang.javascript:
if (top.Content[valu+'answered'] == true)

if (top.Content[valu+'answered'])

True?

Absolutely.

Might need a window reference in there though, never bothered to test it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top