Solved

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

Posted on 2008-10-07
4
668 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
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
AdiF earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now