Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transfer values of select box from popup to textbox in a parent window 2

Status
Not open for further replies.

daveigh

Programmer
Oct 9, 2003
105
my prob is, i want to transfer the values of the 3 select boxes to a parent window named opener. but whenever i try to, i always get this error: expected identifier.

i transfer the value of the select box (located in a popup window) to a textbox (located in parent window, named opener):

opener.document.form1.["p_quantity" + c]value = document.form2.p_quantity.value;

i tried debugging and found out that the error comes from this line:

alert(opener.document.form1.["pid_ordered" + c]value));

can somebody help me? thanks!

_______________CRYOcoustic_____________
 
daveigh,

Try referring to the form element like this:

opener.document.form1["p_quantity" + c].value = document.form2.p_quantity.value;

alert(opener.document.form1["pid_ordered" + c].value));

Give us a shout if that doesn't fix you up.



2b||!2b
 
same error i get.

_______________CRYOcoustic_____________
 
What type of form element are you sending the values to?

2b||!2b
 
i'd like to transfer the value to a parent window with a textbox named p_quantity.

_______________CRYOcoustic_____________
 
Give this a spin:

Code:
<html><head><script>
function mkwin(){
pup = window.open();
pup.document.write('<html><head><script>function snd(val){\n'+
	'opener.document.form1.p_quantity.value = val;}\n'+
	'<\/script></head><body><form name=&quot;test&quot;>\n'+
	'<select name=&quot;sela&quot; onChange=&quot;snd(this.value)&quot;>\n'+
	'<option value=&quot;val1&quot;>Select One</option>\n'+
	'<option value=&quot;val2&quot;>Two</option>\n'+
	'<option value=&quot;val3&quot;>Three One</option></select>\n'+
	'</body></html>\n');
pup.document.close();
pup.focus();
}
</script></head><body>
<form name=&quot;form1&quot;>
<input type=&quot;text&quot; name=&quot;p_quantity&quot; size=&quot;10&quot;>
</form>
<a href=&quot;javascript:mkwin()&quot;>New Form Win</a></body></html>

2b||!2b
 
Sorry, really meant to use the &quot;associative array&quot; syntax
in case you need that &quot;+c&quot; here's that version:
Code:
<html><head><script>
function mkwin(){
pup = window.open();
pup.document.write('<html><head><script>function snd(val){\n'+
	'opener.document.form1[&quot;p_quantity&quot;].value = val;}\n'+
	'<\/script></head><body><form name=&quot;test&quot;>\n'+
	'<select name=&quot;sela&quot; onChange=&quot;snd(this.value)&quot;>\n'+
	'<option value=&quot;val1&quot;>Select One</option>\n'+
	'<option value=&quot;val2&quot;>Two</option>\n'+
	'<option value=&quot;val3&quot;>Three One</option></select>\n'+
	'<p><input type=&quot;button&quot; value=&quot;test&quot; onClick=&quot;'+
  ' alert(opener.document.form1[\'p_quantity\'].value)&quot;>\n'+
	'</body></html>\n');
pup.document.close();
pup.focus();
}
</script></head><body>
<form name=&quot;form1&quot;>
<input type=&quot;text&quot; name=&quot;p_quantity&quot; size=&quot;10&quot;>
</form>
<a href=&quot;javascript:mkwin()&quot;>New Form Win</a></body></html>

2b||!2b
 
this code is so cool! thanks for the help!

_______________CRYOcoustic_____________
 
Hi All,

By looking at your scripts..i wonder can it be used in my VBScript and Javascript.

1. I need to pop-up a Address Book using VBScript to retrieve names from the Database.
2. After the user select the check boxes of names, how to pass back the names in the textbox in the parent window. Which is similar to Hotmail or Yahoo address Book.
3. The pop-up close by itself once finish selecting.

Thanks in advance.

Regards
icy111
 
icy111,

You can add a &quot;self.close()&quot; in the pop-up...

There is no problem using JavaScript and VBScript on the
same page either.

Code:
<html><head><script>
function mkwin(){
pup = window.open();
pup.document.write('<html><head><script>function snd(val){\n'+
    'opener.document.form1[&quot;p_quantity&quot;].value = val; self.close();}\n'+
    '<\/script></head><body><form name=&quot;test&quot;>\n'+
    '<select name=&quot;sela&quot; onChange=&quot;snd(this.value)&quot;>\n'+
    '<option value=&quot;val1&quot;>Select One</option>\n'+
    '<option value=&quot;val2&quot;>Two</option>\n'+
    '<option value=&quot;val3&quot;>Three One</option></select>\n'+
    '</form></body></html>\n');
pup.document.close();
pup.focus();
}
</script></head><body>
<form name=&quot;form1&quot;>
<input type=&quot;text&quot; name=&quot;p_quantity&quot; size=&quot;10&quot;>
</form>
<a href=&quot;javascript:mkwin()&quot;>New Form Win</a></body></html>

2b||!2b
 
IS it possible to size the new window that opens..as now..with this code..its a full size popup window..
Could something like
onclick=&quot;NewWindow(this.href,'name','500','400','no');return false;&quot;>
be added
 
aspmonster,

Here's an example that will give you the ability to tailor
the new window. It uses Jeff's new window from the FAQ's:


Code:
<html><head><script>
/*      ###  Jeff's Pop-up in the FAQ's  ###  */
function newWindow(sURL, sName, w, h) {
    //  your new window's width
    var w = w || 640;
    //  your new window's height
    var h = h || 480;
    var sName = sName || (&quot;win&quot; + new Date().getTime());
    
    var ah = window.screen.availHeight;
    var aw = window.screen.availWidth;
    var l = (aw/2) - (w/2);
    var t = (ah/2) - (h/2);
    var sAtts = &quot;location=yes&quot; + 
        &quot;,menubar=yes,resizable=yes,scrollbars=yes&quot; + 
        &quot;,status=yes,toolbar=yes,height=&quot; + h + 
        &quot;,width=&quot; + w + &quot;,top=&quot; + t +&quot;,left=&quot; + l;        
        
pup = window.open(&quot;&quot;, sName, sAtts);
pup.document.write('<html><head><script>function snd(val){\n'+
    'opener.document.form1[&quot;p_quantity&quot;].value = val; self.close();}\n'+
    '<\/script></head><body><form name=&quot;test&quot;>\n'+
    '<select name=&quot;sela&quot; onChange=&quot;snd(this.value)&quot;>\n'+
    '<option value=&quot;val1&quot;>Select One</option>\n'+
    '<option value=&quot;val2&quot;>Two</option>\n'+
    '<option value=&quot;val3&quot;>Three One</option></select>\n'+
    '</form></body></html>\n');
pup.document.close();
pup.focus();
}
</script></head><body>
<form name=&quot;form1&quot;>
<input type=&quot;text&quot; name=&quot;p_quantity&quot; size=&quot;10&quot;>
</form>
<a href=&quot;javascript:newWindow('','test',200,150)&quot;>
New Form Win</a></body></html>

2b||!2b
 
You're welcome, thanks to Jeff for the good pop-up
routine...


2b||!2b
 
hi Lrnmore,

By looking at your scripts:
---------------------------------------
'opener.document.form1[&quot;p_quantity&quot;].value = val; self.close();}\n'+
'<\/script></head><body><form name=&quot;test&quot;>\n'+
'<select name=&quot;sela&quot; onChange=&quot;snd(this.value)&quot;>\n'+
'<option value=&quot;val1&quot;>Select One</option>\n'+
'<option value=&quot;val2&quot;>Two</option>\n'+
'<option value=&quot;val3&quot;>Three One</option></select>\n'+
'</form></body></html>\n');
---------------------------------------------
But, i am retrieving from Database, instead of hardcoding then.
U know how to do it??

Thanks in advance.

regards
icy111
 
icy,

Here's an example where the db info would be held in the
opener and given to the pop-up to create the sel list and
then sent back...
Code:
<html><head><script language=&quot;JavaScript&quot;>
var comp = new Array('Sel One:&quot;&quot;','Dell:dell','Mac:mac','Sony:sony','IBM:ibm');
var print = new Array('Sel One:&quot;&quot;','HP:hp','Epson:epson','OKI:oki');
var scan = new Array('Sel One:&quot;&quot;','Vision:vision','Acer:acer','HP:hp');

/* ### Jeff's Pop-up in the FAQ's ### */
function newWindow(sURL, sName, w, h, arr) {
// your new window's width
var w = w || 640;
// your new window's height
var h = h || 480;
var sName = sName || (&quot;win&quot; + new Date().getTime());
var ah = window.screen.availHeight;
var aw = window.screen.availWidth;
var l = (aw/2) - (w/2);
var t = (ah/2) - (h/2);
var sAtts = &quot;location=yes&quot; + 
&quot;,menubar=yes,resizable=yes,scrollbars=yes&quot; + 
&quot;,status=yes,toolbar=yes,height=&quot; + h + 
&quot;,width=&quot; + w + &quot;,top=&quot; + t +&quot;,left=&quot; + l; 
pup = window.open(&quot;&quot;, sName, sAtts);
/* ### End Jeff's Pop-up ### */

switch (arr){
case 'c_mfg':
currarr = comp;
break;
case 'p_mfg':
currarr = print;
break;
case 's_mfg':
currarr = scan;
break; }

var nwpg = '<html><head><script>function snd(val){\n'+
   'opener.document.form1[&quot;pupsnd&quot;].value = val; self.close();}\n'+
   '<\/script></head><body><form name=&quot;test&quot;>\n'+
    '<select onChange=&quot;snd(this.value)&quot;>';
  for(i=0;i<currarr.length;i++){
    txt = currarr[i].split(&quot;:&quot;);
      nwpg += '<option value=&quot;'+txt[1]+'&quot;>'+txt[0];}
  nwpg += '</select></body></html>';
pup.document.write(nwpg);
pup.document.close();
pup.focus();
}
</script></head><body>
<form name=&quot;form1&quot;>
<select name=&quot;sela&quot; onChange=&quot;newWindow('','test',200,150,this.value)&quot;>
<option value=&quot;&quot;>Sel One</option>   
<option value=&quot;c_mfg&quot;>Computer</option>
<option value=&quot;p_mfg&quot;>Printer</option>
<option value=&quot;s_mfg&quot;>Scanner</option></select>
<p><input type=&quot;text&quot; name=&quot;pupsnd&quot; size=&quot;15&quot;>
</form>Select an Item</body></html>

2b||!2b
 
Hi Lrnmore,

But i don't quite understand your code...
If i am using access db.

Here is my coding:
Dim strSQL
strSQL =&quot;SELECT username, userid from tblUser&quot;

Trying to execute the SQL query above.. then by using a do..while ..loop to display the check boxes...next to the username.All these names and check boxes are in the pop up window.

After the user select the check boxes, the pop up window show close. And based on the selection of the check boxes, the names should display in the parent window's textbox.

If anyone can help me....thanks a lot...

Regards
icy111
 
Hi icy,

You have a couple of options,

1) Using javascript you can build a url string based on
user selctions:


Then return an &quot;asp&quot; generated page to be the content of
the &quot;pop-up&quot;, based on the value sent in that url.

2) The point of my example was that if you wanted to create
the pop-up at the client you could generate &quot;arrays&quot; to
hold your db info. and then do with it what you want,
that would be easy enough using your loop.

What amounts of info are we talking about?
Which option would you think you might want to use, or maybe
you have more questions..

2b||!2b
 
Hi Lrnmore

Thanks for your fast response.
The data i wish to display is just names. For user select.

regards
icy111
 
Hi lrnmore (and any others who think they could tackle this)

You seem to be a guy who is quite capable when it comes to JS and was wondering if you could give me a hand creating a...well...i'll describe it:

I am creating a MSG system on my website, and need to do a send to multiple usernames form area. You click on a link which loads a page with all the members and check boxes next to them, and you check the boxes of ppl u want to send to, click an &quot;add&quot; button, and then the window would be closed and in the formbox would be the users u selected seperated by a comma, for instance.

I have already crawled the web for info on how to do this but i am unsuccessful.

Thanks in advance for any help

a55m0nk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top