Solved

opening popup windows and passing values between them

Posted on 2004-08-02
6
1,772 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
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

 
LVL 36

Accepted Solution

by:
Zyloch earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Yea, same way:

opener.function_name();

Regards,
${Zyloch}
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

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…
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…

763 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

10 Experts available now in Live!

Get 1:1 Help Now