RadarBob
07-12-2002, 02:57 PM
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?
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)) :D
allida77
07-12-2002, 04:05 PM
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.
RadarBob
07-12-2002, 04:42 PM
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"
allida77
07-12-2002, 06:34 PM
could you post some code?
RadarBob
07-12-2002, 08:48 PM
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"?
<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"><--empty--></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>
Hi Bob,
<script language="JavaScript" type="text/javascript">
<!--
initialize(document.forms[0]);
//-->
</script>
( •) (• )
>>V
>>
RadarBob
07-15-2002, 05:15 PM
Originally posted by Owl
[B]Hi Bob,
<script language="JavaScript" type="text/javascript">
<!--
initialize(document.forms[0]);
//-->
</script>
:thumbsup: 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"