Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1783
  • Last Modified:

opening popup windows and passing values between them

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
SOBKing
Asked:
SOBKing
  • 3
  • 2
1 Solution
 
SweatCoderCommented:
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
 
ZylochCommented:
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
 
SOBKingAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ZylochCommented:
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
 
SOBKingAuthor Commented:
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
 
ZylochCommented:
Yea, same way:

opener.function_name();

Regards,
${Zyloch}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now