Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing inputs to a child window

Status
Not open for further replies.

tridom

Programmer
Mar 15, 2004
12
US
How can I pass inputs using window.open from a parent to a child window without using the querystring? I need to pass them to the child window and then get them back into VBScript(or at least HTML), so I can reprint the form in the child.

I can get them passed into an array in the child window, but can't figure out how to pull them out of the array to either VBScript or HTML.

Any help would be appreciated.

 
If you have the data in an array in the child window, why don't you just reference the array to get the data out?

Dan
 
Dan,

That's my problem. Admittedly, I'm not real experienced with javascript and so I don't know how to reference the array to pull them out. I found the code for passing them to the child window and printing them on screen, but I don't know how to pull them.

Here's the code that passes it from the parent:

<script language="javascript">
<!--
var values=new Array();
function ReadValues(){

var theForm=document.forms[0];
var count=0;
for(var x=0;x<theForm.elements.length;x++){
if(theForm.elements[x].type!="submit"){
//it's a value to pass...
   values[count++]=theForm.elements[x].value;}
 }
}
function Launch(){
    var strLastName=document.DrugTest.LastName.value;
    ReadValues();
    var win=window.open("DrugTestWord.asp","TheWin","");
    return false;
}
//-->
</script>

And in the child is:
<script language="JavaScript">
function GetTheValues() {    
var theOpener=window.opener;    
var theValues=theOpener.values;
var strName=theOpener.DrugTest.LastName.value;
document.write(strName)    
var msg="";    
for(var x=0;x<theValues.length;x++){        
msg+="Value "+(x+1)+": "+(theValues[x])+"<BR>";    
}    
document.write(msg);
}
</script>

That prints them to screen when you return GetThe Values() in the OnLoad event for the form, but I need to pull the valuables into variables so I can build the form and send it to MS Word.

Thanks for the help.
 

Hmmm.. I notice that you are opening an ASP page, which means you will have server-side scripting available to you.

Why not get the parent window to submit to an ASP page, instead of opening a child window? That way, you can build the form server-side, instead of relying on client-side Javascript.

Dan
 
Haven't given a lot of thought to that to tell you the truth. It needs to be a pop-up window so it allows the first window to stay open. The only reason for the pop-up window is so they can manipulate the form in MS Word (save it to disk, print it, etc.).We've always used window.open to open po-ups, so that's the first thing that came to mind. But, I've never had to do a pop-up where I needed to pass variables from the main window to the pop-up (with the exception of small ones that I could pass through the querystring). The number of variables I need to pass in this case exceeds the amount I can pass in a querystring and request.form doesn't work in a pop-up. Therein lies my whole dilemma. I didn't even think about trying it strictly server-side.
 
Hey Dan- think I may have it! I figured out that document.write will write input boxes to the HTML form, so I cna pull the values out of the array into hidden fields and re-submit it server side. The second form should open in the same child window, so it will look like a single pop-up. Whatta ya think?

I really do appreciate the help.
 
Document write will work - the only thing you need to know is that users with Javascript turned off won't be able to use your soltuion... But that's a very small percentage these days, so unless you have accessibility concerns, etc, then go with it as a client-side solution ;o)

Dan
 
Thanks Dan. I got it all figured out once you mentioned server side. Sometimes just need to talk to someone to spark the ol' brain cells.

Javascript enabling is not a problem. The clients are a captive audience, so we can make sure all the machines have javascript enabled. Thanks for the assist!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top