...

View Full Version : reference the opener



daraptor
02-07-2007, 06:00 PM
hey guyz....this is regardin referencin the opener.....i mean..am tryin to populate a textbox in parent using child window......i got it all worked out....but when am tryin the add one more form it does'nt work..can anyone tell me y its not workin....am addin the html codes below...plz chk that and lemme know what is wrong.............

parent.html........

<SCRIPT LANGUAGE="JavaScript">
<!--

function showList() {
sList = window.open("stocklist.html", "list", "width=150,height=210");
}

function remLink() {
if (window.sList && window.sList.open && !window.sList.closed)
window.sList.opener = null;
}

// -->
</SCRIPT><FORM NAME="stockForm">Enter your favorite tech stock:
<INPUT TYPE="text" NAME="stockBox" SIZE="10" VALUE="">
<INPUT TYPE="button" VALUE="list" onClick="showList()">
</FORM>

child window....(stockList.html)

<SCRIPT LANGUAGE="JavaScript">
<!--

function pick(symbol) {
if (window.opener && !window.opener.closed)
window.opener.document.stockForm.stockBox.value = symbol;
window.close();
}

// -->
</SCRIPT>
</HEAD>
<BODY>
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5">
<TR BGCOLOR="#cccccc"><TD><B>NYSE</B></TD><TD><B>NASDAQ</B></TD></TR>
<TR><TD><A HREF="javascript:pick('AOL')">AOL</A></TD>
<TD><A HREF="javascript:pick('CSCO')">CSCO</A></TD></TR>
<TR><TD><A HREF="javascript:pick('CPQ')">CPQ</A></TD>
<TD><A HREF="javascript:pick('INTC')">INTC</A></TD></TR>
<TR><TD><A HREF="javascript:pick('NOK')">NOK</A></TD>
<TD><A HREF="javascript:pick('SUNW')">SUNW</A></TD></TR>
<TR><TD><A HREF="javascript:pick('LU')">LU</A></TD>
<TD><A HREF="javascript:pick('AMZN')">AMZN</A></TD></TR>
<TR><TD><A HREF="javascript:pick('T')">T</A></TD>
<TD><A HREF="javascript:pick('MSFT')">MSFT</A></TD></TR>
</TABLE>
</BODY>

i tried renamin all the field names and form names ,,,but am gettin to work with the 1st form,but 2nd form is not workin....plz lemme know what i have to change in order to get this workin.....thnx.........

Mr J
02-07-2007, 07:29 PM
Here's one possiblity



<SCRIPT type="text/javascript">
<!--

function showList(n) {
num=n
sList = window.open("stocklist.html", "list", "width=150,height=210");
}

function remLink() {
if (window.sList && window.sList.open && !window.sList.closed)
window.sList.opener = null;
}

// -->
</SCRIPT>
<FORM NAME="stockForm">Enter your favorite tech stock:
<INPUT TYPE="text" NAME="stockBox" SIZE="10" VALUE="">
<INPUT TYPE="button" VALUE="list" onClick="showList(1)">
</FORM>

<FORM NAME="form2">Enter your favorite tech stock:
<INPUT TYPE="text" NAME="form2inputname" SIZE="10" VALUE="">
<INPUT TYPE="button" VALUE="list" onClick="showList(2)">
</FORM>


Child window


<SCRIPT type="text/javascript">
<!--

function pick(symbol) {
if(window.opener)

if(opener.num==1){
window.opener.document.forms["stockForm"]["stockBox"].value = symbol;
}

if(opener.num==2){
window.opener.document.forms["form2"]["form2inputname"].value = symbol;
}
window.close();
}

// -->
</SCRIPT>


<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5">
<TR BGCOLOR="#cccccc"><TD><B>NYSE</B></TD><TD><B>NASDAQ</B></TD></TR>
<TR><TD><A HREF="javascript:pick('AOL')">AOL</A></TD>
<TD><A HREF="javascript:pick('CSCO')">CSCO</A></TD></TR>
<TR><TD><A HREF="javascript:pick('CPQ')">CPQ</A></TD>
<TD><A HREF="javascript:pick('INTC')">INTC</A></TD></TR>
<TR><TD><A HREF="javascript:pick('NOK')">NOK</A></TD>
<TD><A HREF="javascript:pick('SUNW')">SUNW</A></TD></TR>
<TR><TD><A HREF="javascript:pick('LU')">LU</A></TD>
<TD><A HREF="javascript:pick('AMZN')">AMZN</A></TD></TR>
<TR><TD><A HREF="javascript:pick('T')">T</A></TD>
<TD><A HREF="javascript:pick('MSFT')">MSFT</A></TD></TR>
</TABLE>

daraptor
02-08-2007, 04:09 AM
Here's one possiblity



<SCRIPT type="text/javascript">
<!--

function showList(n) {
num=n
sList = window.open("stocklist.html", "list", "width=150,height=210");
}

function remLink() {
if (window.sList && window.sList.open && !window.sList.closed)
window.sList.opener = null;
}

// -->
</SCRIPT>
<FORM NAME="stockForm">Enter your favorite tech stock:
<INPUT TYPE="text" NAME="stockBox" SIZE="10" VALUE="">
<INPUT TYPE="button" VALUE="list" onClick="showList(1)">
</FORM>

<FORM NAME="form2">Enter your favorite tech stock:
<INPUT TYPE="text" NAME="form2inputname" SIZE="10" VALUE="">
<INPUT TYPE="button" VALUE="list" onClick="showList(2)">
</FORM>


Child window


<SCRIPT type="text/javascript">
<!--

function pick(symbol) {
if(window.opener)

if(opener.num==1){
window.opener.document.forms["stockForm"]["stockBox"].value = symbol;
}

if(opener.num==2){
window.opener.document.forms["form2"]["form2inputname"].value = symbol;
}
window.close();
}

// -->
</SCRIPT>


<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5">
<TR BGCOLOR="#cccccc"><TD><B>NYSE</B></TD><TD><B>NASDAQ</B></TD></TR>
<TR><TD><A HREF="javascript:pick('AOL')">AOL</A></TD>
<TD><A HREF="javascript:pick('CSCO')">CSCO</A></TD></TR>
<TR><TD><A HREF="javascript:pick('CPQ')">CPQ</A></TD>
<TD><A HREF="javascript:pick('INTC')">INTC</A></TD></TR>
<TR><TD><A HREF="javascript:pick('NOK')">NOK</A></TD>
<TD><A HREF="javascript:pick('SUNW')">SUNW</A></TD></TR>
<TR><TD><A HREF="javascript:pick('LU')">LU</A></TD>
<TD><A HREF="javascript:pick('AMZN')">AMZN</A></TD></TR>
<TR><TD><A HREF="javascript:pick('T')">T</A></TD>
<TD><A HREF="javascript:pick('MSFT')">MSFT</A></TD></TR>
</TABLE>


hey mr J thanx for the help it is workin for two of the forms....awesome man..thank u very much.....appreciate it...i have one more question though....i got 2 forms workin.....what if i need 6 forms .......what shud i do to add 6 forms....thanx for the help....

Mr J
02-08-2007, 01:50 PM
Add another if statement for each form to the script in the child window changing the form name and element name to suit the forms and in the onclick event for the forms button put the number relating to the form number

You could also use the switch statement or go with the form and elements array

daraptor
02-08-2007, 07:45 PM
Add another if statement for each form to the script in the child window changing the form name and element name to suit the forms and in the onclick event for the forms button put the number relating to the form number

You could also use the switch statement or go with the form and elements array


<SCRIPT type="text/javascript">
<!--

function pick(symbol)
{
if(window.opener)

if(opener.num==1){
window.opener.document.forms["stockForm"]["stockBox"].value = symbol;
}
if(opener.num==2){
window.opener.document.forms["form2"]["form2inputname"].value = symbol;
}
if(opener.num==3){
window.opener.document.forms["form3"]["form3inputname"].value = symbol;
}
if(opener.num==4){
window.opener.document.forms["form4"]["form4inputname"].value = symbol;
}
if(opener.num==5){
window.opener.document.forms["form5"]["form5inputname"].value = symbol;
}
if(opener.num==6){
window.opener.document.forms["form6"]["form6inputname"].value = symbol;
}
window.close();
}

// -->
</SCRIPT>
hey mr J thanx for the help man....i pasted what i did.....but am unable to populate forms 3,4,5,6.........forms 1 and 2 r workin great.....and i also changed the onclick showlist(n) to the respective numbers like onclick showlist(3),onclick showlist(4), onclick showlist(5), onclick showlist(6)......but am unable to populate text boxes.....plz see the javascript code and lemme know what i shud do ...thank u very much for helpin

daraptor
02-09-2007, 09:57 PM
hey Mr J got it working man.....thanx for the help.......



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum