Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 682
  • Last Modified:

How to pass parameters to anorher window and then get values back in Javascript

I have a HTML form. When an user clicks a button, I want to open another window and display
a range of selection parameters. When I do this, I need to pass the user's details to the window. Then, win the new window, when the user enters a range. I display a set of orders and they select an order.
I want to pass that order and the user details back to the parent form so that I can verify the user and then use the order for further processing.

 
0
narayanhy
Asked:
narayanhy
  • 2
  • 2
1 Solution
 
AdiFCommented:
You can add the onClick attribute inside the button to pop up the window using window.open in JavaScript.  For example:

<input type=button onClick=''window.open("http://myURL", "myWindowName");">

Then in the webpage that opens in the new window, you can freely access and read/write to/from any values in the parent window.  You can load variables by incorporating the JavaScript window.onload method and use it to call a function that will load all the variables like this:

window.parent.document.forms[0].objectname.value

Likewise you can set new values like this: window.parent.document.forms[0].objectname.value="new value";
0
 
narayanhyAuthor Commented:
Thanks a lot for your hint.
Basically, When the user selects an order number in the child , I want to display it in the parent form. That is when the user clicks an order number, I want the child window to close and the parent window to display the value selected in the child.
What is the best way to code this ?

Cheers  
0
 
AdiFCommented:
Well in the child window I would add an onClick event to set the parent window's variable to the selectoed order number as described in my first comment.  For example:

<input type=radio onClick="window.parent.document.getElementById('myDivToDisplayTheOrderNumber').innerHTML=this.value; window.close();" value=order12345>

That will set the HTML of a <div> tag in the parent window to show the order number that was clicked on, and instantly close its own window (child window) at the same time.
0
 
narayanhyAuthor Commented:
Hi Adif,

Please help me with the following example.

I am not bale to display the variable I passed to the child form. I tried accessing it from teh parent form. I did not get any succss there also.  

Also, How do I tell the window to redisplay it again ? i.e reexecute the Onload function etc. ?  

Regards
The script to call the window in parent 
 
function openSel8(selectFile1) {
        var win=window.open(selectFile1,'Select','width='+0.8*screen.width+',height='+0.8*screen.height+
                         ',resizable=1,location=0,toolbar=0,scrollbars=yes,top='+0.1*screen.height+',left='+0.1*screen.width);
        win.focus();
           }
 
<form name="Form1" id="Form1" method="POST" action="">
if (type == "R")  {
 
	    form.action = openSel8('fin_InvoicePartRange.htm?DealerCd=xxDealerCd'); 
 
 
 
In child window, I put the following code to display the passed value. But, I get "Null value or not an object error."  
 
var Dealer1 = parent.document.forms[0].xxDealerCd.value;
		alert(Dealer1);  
 
I also tried straight away accessing teh variable DealeCd in the window. That also did not work.

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now