Random Number Blues

H

Heath

Using MSIE 5+ Heath writes:

My problem deals with working with window objects between
pages as follows:

My Introduction page contains a link to my Action page.
The onClick of that link creates a series of random numbers
that are appended to the end of the url of the Action page.
After initiating the link the URL of the Action page
looks like this:

http://Action.htm?61,65,24,22 etc x 16.

Now a user chooses two of those numbers, say 61 and 24,
from the Action page and they are sent to a Pop-Up page.

On the Pop-up page the user has to choose between
the two numbers, say he or she chooses 61.

**How do I get that number, 61, back to the Action page?**

The problem I am having is that I don't know how
to set the Action page as an object, because of adding
the random numbers on the end it makes it tuff.

Normally I would create an object like

var ActionPage = window.open("Action.htm", "Action"),

but that won't work because of the random Numbers.

I had to send them from the Introduction page, therefore
the Action page object I created on the Introduction page
is wiped out when the Action page JavaScript loads.

I also can't send anything back to the Action page's URL
because I need it to stay how it is for the random numbers.

Final Notes: I don't know CGI so I can't use it yet. Although
it is bad form, this page is completely dependent on JavaScript
otherwise I would have to write 4000 pages, which won't work.
 
L

Lee

(e-mail address removed) said:
Using MSIE 5+ Heath writes:

My problem deals with working with window objects between
pages as follows:

Your Subject line was poorly chosen, since it gives the
impression that you are having trouble with the Math.random()
method.
My Introduction page contains a link to my Action page.
The onClick of that link creates a series of random numbers
that are appended to the end of the url of the Action page.
After initiating the link the URL of the Action page
looks like this:

http://Action.htm?61,65,24,22 etc x 16.

Now a user chooses two of those numbers, say 61 and 24,
from the Action page and they are sent to a Pop-Up page.

Is the "Pop-Up page" opening in a new window, as the name
seems to imply (we've already been fooled once)? If so,
that Window can refer back to the Action page via it's
"opener" attribute.
On the Pop-up page the user has to choose between
the two numbers, say he or she chooses 61.

**How do I get that number, 61, back to the Action page?**

Normally I would create an object like

var ActionPage = window.open("Action.htm", "Action"),

but that won't work because of the random Numbers.

I don't see how it will help, but you can use variables
in the window.open() call, or you can create the URL as
a variable:

var sep="?";
var URL="Action.htm";
for(var i=0;i<16;i++){
URL+=sep+Math.floor(Math.random()*100);
sep=",";
}
var ActionPage=window.open(URL,"Action");
 
H

Heath

This is exactly what I tried (using the var x = window.open(),
but it just creates a eternal loop. Because the random
numbers can only be generate once, at the beginning, per
user session.

The basic flow is:
random numbers = R

Intro >> 64R >> Action
User chooses two numbers
Action >> 2R >> Pop-up (external window)
User chooses one of the two numbers
Pop-up >> 1R >> Action

The problem is I assign var Action = window.open("Action.htm")
in the Intro page, but when "Action.htm" loads it has a .js file
attached to it so the Intro .js is wiped out.

I guess the only way I could solve it is if there is a way to
set global variables from within a function.

(see below)
Your Subject line was poorly chosen, since it gives the
impression that you are having trouble with the Math.random()
method.
It's true, but it all revolves around the problems I have in
generating 64 unique random numbers.
Is the "Pop-Up page" opening in a new window, as the name
seems to imply (we've already been fooled once)? If so,
that Window can refer back to the Action page via it's
"opener" attribute.

Yes the Pop-Up opens a new page. I am not familiar with this
attribute so I will check it out.
 
H

Heath

Well, the opener thing works perfectly, my life is now
100% easier.

Thank you very, very much Lee.
 

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top