Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 13th, 2004, 03:19 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default Nexting Code

I have a page that someone else developed and it has a problem with the navigation. First, here is the pertinent code...

// create array of all quiz pages in the entire quiz
var quiz = new Array()


quiz[0] = new quizPage("intro_home.htm")
quiz[1] = new quizPage("intro_q1.htm")
quiz[2] = new quizPage("intro_q2.htm")
quiz[3] = new quizPage("intro_q3.htm")
quiz[4] = new quizPage("intro_q4.htm")
quiz[5] = new quizPage("intro_q5.htm")
quiz[6] = new quizPage("intro_q6.htm")
quiz[7] = new quizPage("intro_q7.htm")
quiz = new quizPage("intro_q8.htm")
quiz[9] = new quizPage("intro_q9.htm")
quiz[10] = new quizPage("intro_q10.htm")
quiz[11] = new quizPage("intro_sum.htm")

// navigate to next quiz page in sequence
function goNext() {
  var currPage, i
  for (i=0; i<(quiz.length-1); i++)
  {
    if (parent.main.location.href.indexOf(quiz[i].src) != -1)
    {
      parent.main.location.href = quiz[i+1].src
      break
    }
  }
}

Problem is that when the intro_sum.htm page is displayed and the end user clicks on the next button (which kicks the gonext function into action), they get an error because parent.main.location.href is undefined. I tried simply putting a new line into the array to fix it, but that did not work and I even tried changing the if statement to an if else statement. Anyone have any ideas?

Thanks in advance for your assistance.

Clay Hess
__________________
Clay Hess
 
Old October 14th, 2004, 10:25 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Has anyone read this and had thoughts that would help?

Clay Hess
 
Old October 14th, 2004, 10:42 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Clay,

By the look of it you are trying to reference an element outside of the array - when "intro_sum.htm" is the page in main you are referencing quiz[11 + 1].

What do you want to happen when someone clicks next on "intro_sum.htm"?

Cheers,

Chris

 
Old October 14th, 2004, 10:47 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Chris,

thanks for the assist. All I want to be able to do is to send the user to a menu page and replace this frameset. Thoughts?

Quote:
quote:Originally posted by ChrisScott
 Hi Clay,

By the look of it you are trying to reference an element outside of the array - when "intro_sum.htm" is the page in main you are referencing quiz[11 + 1].

What do you want to happen when someone clicks next on "intro_sum.htm"?

Cheers,

Chris

Clay Hess
 
Old October 14th, 2004, 10:55 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Clay,

Something like this should work...
Code:
function goNext() {
    var currPage, i
    for (i=0; i<(quiz.length-1); i++) 
    {
        if (parent.main.location.href.indexOf(quiz[i].src) != -1) 
        {
            if(i + 1 == quiz.length){
                top.location.href = "myMenuPage.htm";
            }else{
                parent.main.location.href = quiz[i+1].src
                break
            }    
        }
    }
}
HTH,

Chris

 
Old October 14th, 2004, 12:49 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Chris I see what you are trying to do and I tried something similiar. I also tried it the way you have it coded and I still get an error. It is telling me that parent.main.location.href is null or not an object. WHat do you think?

Quote:
quote:Originally posted by ChrisScott
 Hi Clay,

Something like this should work...
Code:
function goNext() {
    var currPage, i
    for (i=0; i<(quiz.length-1); i++) 
    {
        if (parent.main.location.href.indexOf(quiz[i].src) != -1) 
        {
            if(i + 1 == quiz.length){
                top.location.href = "myMenuPage.htm";
            }else{
                parent.main.location.href = quiz[i+1].src
                break
            }    
        }
    }
}
HTH,

Chris

Clay Hess
 
Old October 14th, 2004, 04:36 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try referencing the main frame with:

top.frames.main
or
parent.frames.main

Instead of:

parent.main

Also, make sure the name of the frame is "main", case sensitive.

This may or may not solve your problem. Let me know.

-Snib <><
Try new FreshView 0.2!
There are only two stupid questions: the one you don't ask, and the one you ask more than once ;)
 
Old October 14th, 2004, 07:12 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did not work...any other thoughts?

Quote:
quote:Originally posted by Snib
 Try referencing the main frame with:

top.frames.main
or
parent.frames.main

Instead of:

parent.main

Also, make sure the name of the frame is "main", case sensitive.

This may or may not solve your problem. Let me know.

-Snib <><
Try new FreshView 0.2!
There are only two stupid questions: the one you don't ask, and the one you ask more than once ;)
Clay Hess
 
Old October 15th, 2004, 03:23 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Clay,

This works for me in IE & Mozilla...

frameset
Code:
<html>

<head>
<title></title>
</head>

<frameset cols="200, *">
    <frame name="nav" src="nav.htm"></frame>
    <frame name="main" src="intro_sum.htm"></frame>
</frameset>

</html>
nav.htm
Code:
<html>

<head>
<title></title>
<script type="text/javascript">
// create array of all quiz pages in the entire quiz
var quiz = new Array()

quiz[0] = new quizPage("intro_home.htm")
quiz[1] = new quizPage("intro_q1.htm")
quiz[2] = new quizPage("intro_q2.htm")
quiz[3] = new quizPage("intro_q3.htm")
quiz[4] = new quizPage("intro_q4.htm")
quiz[5] = new quizPage("intro_q5.htm")
quiz[6] = new quizPage("intro_q6.htm")
quiz[7] = new quizPage("intro_q7.htm")
quiz[8] = new quizPage("intro_q8.htm")
quiz[9] = new quizPage("intro_q9.htm")
quiz[10] = new quizPage("intro_q10.htm")
quiz[11] = new quizPage("intro_sum.htm")

// navigate to next quiz page in sequence
function goNext() {
    var currPage, i
    for(i = 0; i < quiz.length; i++) // was i<(quiz.length-1); 
    {
        if (parent.main.location.href.indexOf(quiz[i].src) != -1) 
        {
            if(i + 1 == quiz.length){
                top.location.href = "myMenuPage.htm";        
            }else{
                parent.main.location.href = quiz[i+1].src;
            }
            break
        }
    }
}

function quizPage(src){
    this.src = src;
}

</script>
</head>

<body>

</body>

</html>
intro_sum.htm
Code:
<html>

<head>
<title></title>
</head>

<body>

<input type="button" onclick="parent.nav.goNext();" value="goNext();" />

</body>

</html>
BTW, why do you keep re-posting the last post as a quote?

HTH,

Chris
 
Old October 15th, 2004, 09:22 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Chris,

Thanks for the code suggestion, but it did not work. It is still telling me that parent.main.location.href is null or not an object. Any other thoughts?

As for why it quotes, this message board does that when you reply to a message as opposed to the topic.

Clay Hess





Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM
disable forum code within [code] blocks? nikolai Forum and Wrox.com Feedback 0 October 23rd, 2003 07:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.