Solved

opening popup windows and passing values between them

Posted on 2004-08-02
6
1,773 Views
Last Modified: 2009-12-16
I have a list of members for my webpage stored in a file.

I have created a webpage called (lookup.php) which will generate a listbox full of the members that has an onDblclick event that calls this javascript

function getresult(option) {
     self.opener.form1.member.value = option.value;
     window.close();
}


so basically i have a form with a textbox called member that has a button next to it, when you click that button.. it opens a popup (lookup.php) and when you double click a member thats in the popup it closes the popup and fills in the value for the member textbox

now the problem im having is what if my form isnt called "form1", or what if im not tyring to fill in the "member" textbox but a textbox called referedby, is there a way to pass the popup a pointer to the textbox i want to change?
0
Comment
Question by:SOBKing
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:SweatCoder
ID: 11698802
self.opener.forms[0].member.value  (reference it by collection)

do same idea with textbox.

or. . .you can pass the name of the object into your function and use "eval" to build the statement.
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11698882
To clarify what SweatCoder said, you can reference it by array index. The downside to this is that you must know which form your form is on the page, and it always needs to be constant. Same with the element:

self.opener.forms[0].elements[2].value for instance.


You can also add more parameters to the function, such as:

function getresult(option,frmname,txtfieldname) {
     self.opener.frmname.textfieldname.value = option.value;
     self.close();
}

You have to pass the main page frmname and txtfieldname, but it allows variety. Also, just as a remark, your when you pass option to the function, it's something like: yourselectbox.options[yourselectbox.selectedIndex] right? where yourselectbox is however you reference your select, either by getElementById or formname.selectboxname.

Regards,
${Zyloch}
0
 

Author Comment

by:SOBKing
ID: 11698943
ya i cant do it by the index, because im not sure where it will be on the form

so how would i make the main page pass the form name and box name to the popup??



oh and Zyloch heres an example of the select

<select name="member_list" size="5" width="200" onDblclick=getresult(member_list)>
     <option value="01" selected>MxD_420</option>
     <option value="02">MxD_KuRuPT</option>
     <option value="03">MxD_I-Suck</option>
     <option value="04">MxD_KillMe</option>
     <option value="05">MxD_LittleKid</option>
</select>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 36

Accepted Solution

by:
Zyloch earned 250 total points
ID: 11699054
First change this: <select name="member_list" size="5" width="200" onDblclick=getresult(member_list)>
to this:
<select name="member_list" size="5" width="200" onDblclick="getresult(this.options[this.selectedIndex]);">

You can pass the form name and text field name two ways. The first is to attach it to the end of the URL when you use window.open to open the popup. Then, use Javascript string functions to cut apart the url.

The second, easier, way is, on your main page, create two global variables (they're global if they're not in a function or loop) named, for instance,

var thisFrmName = "THE_NAME_OF_THE_FORM";
var thisTxtName = "THE_NAME_OF_TEXTFIELD";

Then, you can call getresult() like this: (if you add the extra two parameters I did in my example):

onDblclick="getresult(this.options[this.selectedIndex],opener.thisFrmName,opener.thisTxtName);"

Regards,
${Zyloch}
0
 

Author Comment

by:SOBKing
ID: 11699527
thanks!

one other quick question...


is it possible to call a function from the popup thats in the main window who opened the popup??
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11699588
Yea, same way:

opener.function_name();

Regards,
${Zyloch}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

911 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

21 Experts available now in Live!

Get 1:1 Help Now