Random Number Blues

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Heath

    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("Ac tion.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.
  • Lee

    #2
    Re: Random Number Blues

    hjweaver@email. com said:[color=blue]
    >
    >Using MSIE 5+ Heath writes:
    >
    >My problem deals with working with window objects between
    >pages as follows:[/color]

    Your Subject line was poorly chosen, since it gives the
    impression that you are having trouble with the Math.random()
    method.
    [color=blue]
    >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.[/color]

    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.
    [color=blue]
    >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?**[/color]

    [color=blue]
    >Normally I would create an object like
    >
    >var ActionPage = window.open("Ac tion.htm", "Action"),
    >
    >but that won't work because of the random Numbers.[/color]

    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.f loor(Math.rando m()*100);
    sep=",";
    }
    var ActionPage=wind ow.open(URL,"Ac tion");

    Comment

    • Heath

      #3
      Re: Random Number Blues

      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("Ac tion.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:[color=blue][color=green]
      >>My problem deals with working with window objects between
      >>pages as follows:[/color]
      > Your Subject line was poorly chosen, since it gives the
      > impression that you are having trouble with the Math.random()
      > method.[/color]
      It's true, but it all revolves around the problems I have in
      generating 64 unique random numbers.
      [color=blue][color=green]
      >>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,[/color]
      >[color=green]
      >>from the Action page and they are sent to a Pop-Up page.[/color]
      >
      > 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.[/color]

      Yes the Pop-Up opens a new page. I am not familiar with this
      attribute so I will check it out.
      [color=blue]
      > 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.f loor(Math.rando m()*100);
      > sep=",";
      > }
      > var ActionPage=wind ow.open(URL,"Ac tion");[/color]


      Comment

      • Heath

        #4
        Re: Random Number Blues

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

        Thank you very, very much Lee.

        Comment

        Working...