473,387 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Random Number Blues

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.
Jul 20 '05 #1
3 2666
Lee
hj******@email.com 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");

Jul 20 '05 #2
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)

Lee wrote:
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.

It's true, but it all revolves around the problems I have in
generating 64 unique random numbers.
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.


Yes the Pop-Up opens a new page. I am not familiar with this
attribute so I will check it out.
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");

Jul 20 '05 #3
Well, the opener thing works perfectly, my life is now
100% easier.

Thank you very, very much Lee.

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Virus | last post by:
Ok well what I am trying to do is have 1.) the background color to change randomly with 5 different colors.(change on page load) 2,) 10 different quotes randomly fadeing in and out in random...
10
by: Sonoman | last post by:
Hi all: I am trying to write a simple program that simulates asking several persons their birth day and it counts how many persons are asked until two have the same birth day. The problem that I...
4
by: Jack | last post by:
I have two files: sort_comparison.c++ my_sort.h sort_comparison.c++ calls this code in my_sort.h: void my_sort::fillArray(int arr,int n) { // const int random_number_range=1000000;
70
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
10
by: Johnny Snead | last post by:
Hey guys, Need help with this random sort algorithm private void cmdQuestion_Click(object sender, System.EventArgs e) { Random rnd = new Random(); //initialize rnd to new random object...
5
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible...
4
by: fatimahtaher | last post by:
Hi, I am supposed to create a program that generates a random number and then asks the user to guess the number (1-100). The program tells the user if he guessed too high or too low. If he...
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
2
by: alishaikhji | last post by:
I am working on a program which will need several different integer and float random numbers at different stages, for example: - At one point, I need a random number (float) in the range 0.1 to 10.0...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.