Web Analytics Made Easy -
StatCounter Pass stuff to new window via Session Variable array? - CodingForum

Announcement

Collapse
No announcement yet.

Pass stuff to new window via Session Variable array?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pass stuff to new window via Session Variable array?

    I open an new window from a parent window. I want the values from a certain <SELECT> object in the parent page to pre-populate a <SELECT> object in the child page.

    I've tried a Javascript solution but that won't work. The objects in the child page (the <form>) "don't exist yet" when <body ... onload="initialize()"> is done.

    So a session variable might be the ticket. Can an array be a session variable? The books I have on the subject don't show anything other than single-value non-typed variables. How would I declare (in Session_onStart) an array then reference it?

  • #2
    Can an array be a session variable?
    Yes.

    ---file1.asp---
    <%
    'Creating and initializing the array
    Dim MyArray()
    Redim MyArray(2)
    myArray(0) = "hello"
    myArray(1) = "World"

    'Store the array in the Session object.
    Session("StoredArray") = myArray

    Response.Redirect("file2.asp")
    %>

    ---file2.asp---
    <%
    'Retrieve the array from the Session Object
    LocalArray = Session("StoredArray")

    Response.Write(LocalArray(0)&LocalArray(1))
    aspxtreme

    Comment


    • #3
      Instead of putting your onload="initialize()" in the <form> put the function on the bottom of the page. There is no need to use a session variable.
      does this sig match?

      Comment


      • #4
        Originally posted by allida77
        Instead of putting your onload="initialize()" in the <form> put the function on the bottom of the page. There is no need to use a session variable.
        Been there, done that. Doesn't work - *unless I did something wrong? nah. never happens*. Anyway, I get the same error "xxxx is null or not an object"

        Comment


        • #5
          could you post some code?
          does this sig match?

          Comment


          • #6
            Here's the code cut down to the essentials. Just so it's clear.. this code works. If, for example, I tie it to the onfocus="initialize(this.form)" of some textbox (just to arbitrarily pick a convenient object on the form); then click into that textbox then volia! the values are copied, as desired, from the parent page to this page.

            The alert()s in the function are for debugging purposes.

            NOTE: I get the same error when the function call is placed immedialy after </form> or immediately after </body> or immediately after </html>.

            NOTE: I think it is interesting that the error I get is "newList is null or not an object". The error is not flagging "theform" - as if it's been created... As well it should have been. And if it has, why not "newList"?


            Code:
            <html>
            <title>Add Database Keywords</title>
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
            <script language=javascript1.2>
            <!-- Begin
            
            ............. lots of javascript functions here ......................
            
            function initialize(theform) {
               var e = theform.newList.options;
               var originalList = new String ();
               
               for (var i=0; i<window.opener.DBForm.fKeywords.length; i++) {
                   originalList += i + "= " + window.opener.DBForm.fKeywords.options[i].text + "\r";
               }
               alert ("the original list = \r" + originalList);
               originalList = "";
               
               for (var i=0; i<e.length; i++) {
                originalList += i + "= " + e[i].text + "\r";
               }
               alert ("the initial target list = \r" + originalList);
            
               originalList = "";
               
               with (window.opener.DBForm.fKeywords) {
                  for (var i = 0; i < length; i++) {
                     e[i] = new Option(options[i].text, options[i].value);
                  }
               }
            
               for (var i=0; i<theform.newList.length; i++) {
                originalList += i + "= " + e[i].text + "\r";
               }
               alert ("the target list = \r" + originalList);
            }  // initialize()
            
            // End -->
            </script>
            </head>
            
            <body>
            <form>
              <center>
              <table width="-1" border="5" height="350">	
            
                .... stuf in rows....
                  
                .......... heres the object I'm working with ...............
                    <select size="6" name="newList" width="300" multiple tabindex="7"
                     onKeyPress="return findOption(this)">
                       <option value="00">&lt;--empty--&gt;</option>
                    </select>
                    
              </table>
              </center>
            </form>
            
            </body>
            
            </html>
            
            ......... and here's the call to the script to pre-fill the above <SELECT> object............
            
            <script language="JavaScript" type="text/javascript">
            <!--
            initialize(this.form);
            //-->
            </script>
            Last edited by RadarBob; Jul 12, 2002, 03:57 PM.

            Comment


            • #7
              Hi Bob,

              <script language="JavaScript" type="text/javascript">
              <!--
              initialize(document.forms[0]);
              //-->
              </script>

              ( •) (• )
              >>V
              >>
              owl3d.com

              Comment


              • #8
                Originally posted by Owl
                [B]Hi Bob,

                <script language="JavaScript" type="text/javascript">
                <!--
                initialize(document.forms[0]);
                //-->
                </script>
                Works great! Three hoots for Owl!!

                The above line is at the bottom of my document, between the </body> and </html> tags and of course not inside a function, which will cause it to execute automatically when the page is built on the client.

                To recap, here's what I am now doing: Adding and deleting, from a child page, a list of words on the parent page. All without redrawing or refreshing the parent page..

                Since the list (a <select> object) can be dynamically refreshed (vis-a-vis adding rows to a <table>) I don't have to refresh/redraw the page - which prevents the entire nasty cycle of:
                • validate an incomplete form - and "shortcircuiting" the required field validations so I can:
                • save to the database
                • fetch from the database
                • rebuild the page on the server
                • send page to client
                • re-display page


                P.S. vis-a-vis (veez a vee) "as compared to and contrasted with"
                Last edited by RadarBob; Jul 15, 2002, 12:19 PM.

                Comment

                Working...
                X