Solved

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

Posted on 2008-10-07
4
672 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to pass JavaScript generated HTML text form values to PHP? 5 38
VBScript on Html 15 47
Json Schema 8 32
Button function on table is in trouble 3 21
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

861 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