Solved

opening popup windows and passing values between them

Posted on 2004-08-02
6
1,778 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
[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
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
Suggested Courses

632 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