Solved

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

Posted on 2008-10-07
4
675 Views
Last Modified: 2012-05-05
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
Comment
Question by:narayanhy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
AdiF earned 250 total points
ID: 22665091
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
 

Author Closing Comment

by:narayanhy
ID: 31504071
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
 
LVL 2

Expert Comment

by:AdiF
ID: 22674282
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
 

Author Comment

by:narayanhy
ID: 22699749
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question