Solved

opening popup windows and passing values between them

Posted on 2004-08-02
6
1,776 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

738 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