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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select data from pop up window and display in main form 1

Status
Not open for further replies.

kiwieur

Technical User
Apr 25, 2006
200
GB
Hi,

I have a form and I am trying to add data to certain text fields based on data that is displayed in a popup window.

this is how i am displaying the popup window

Code:
<td bgcolor="#CCFFCC"><a href='JavaScript:openPopWin("[URL unfurl="true"]http://SomeNet/Enquiries/ExSampleAddress.asp?<%=[/URL] Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "companynumber=" & rsDetails.Fields.Item("companynumber").Value %>", 600, 350,"scrollbars", 400, 250)' class="TextLeft12px">Search</a></td>

And this is the code in the popup window
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../Connections/RNetLive.asp" -->
<%
Dim rsAddresses__cName
rsAddresses__cName = "121332"
If (request.QueryString("companynumber")    <> "") Then 
  rsAddresses__cName = request.QueryString("companynumber")   
End If
%>
<%
Dim rsAddresses
Dim rsAddresses_cmd
Dim rsAddresses_numRows

Set rsAddresses_cmd = Server.CreateObject ("ADODB.Command")
rsAddresses_cmd.ActiveConnection = MM_RNetLive_STRING
rsAddresses_cmd.CommandText = "SELECT * FROM tblEQ_Addresses WHERE ? = companynumber" 
rsAddresses_cmd.Prepared = true
rsAddresses_cmd.Parameters.Append rsAddresses_cmd.CreateParameter("param1", 200, 1, 255, rsAddresses__cName) ' adVarChar

Set rsAddresses = rsAddresses_cmd.Execute
rsAddresses_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
rsAddresses_numRows = rsAddresses_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SampleAddress</title>
<link href="../Styles/RigidTextStyles.css" rel="stylesheet" type="text/css" />
[COLOR=red][b]<script language=javascript>
function setOther(){
window.returnValue1 = frmAddress.txtAdd1.value
window.returnValue2 = frmAddress.txtAdd2.value
window.returnValue3 = frmAddress.txtAdd3.value
window.returnValue4 = frmAddress.txtPCode.value
}
</script>[/b][/color]
</head>

<body>
<form id="frmAddress" name="frmAddress" method="post" action="">
  <p>&nbsp;</p>
  <table width="30%" border="0" align="center" class="tblbodaSolid">
    <tr>
      <td colspan="6" class="tblHeaderCapsGreen">select address</td>
    </tr>
    <tr class="tblHeaderCaps11px">
      <td>RecId</td>
      <td>add 1</td>
      <td>add 2</td>
      <td>add 3</td>
      <td>post code</td>
      <td>go</td>
    </tr>
    <% 
While ((Repeat1__numRows <> 0) AND (NOT rsAddresses.EOF)) 
%>
    <tr>
      <td><label>
        <input name="txtID" type="text" class="TextCentrePlain10px" id="txtID" value="<%=(rsAddresses.Fields.Item("ID").Value)%>" size="10" maxlength="10" />
      </label></td>
      <td><input name="txtAdd1" type="text" class="TextCentrePlain10px" id="txtAdd1" value="<%=(rsAddresses.Fields.Item("Add1").Value)%>" size="20" maxlength="40" /></td>
      <td><input name="txtAdd2" type="text" class="TextCentrePlain10px" id="txtAdd2" value="<%=(rsAddresses.Fields.Item("Add2").Value)%>" size="20" maxlength="40" /></td>
      <td><input name="txtAdd3" type="text" class="TextCentrePlain10px" id="txtAdd3" value="<%=(rsAddresses.Fields.Item("Add3").Value)%>" size="20" maxlength="40" /></td>
      <td><label>
        <input name="txtPCode" type="text" class="TextCentrePlain10px" id="txtPCode" value="<%=(rsAddresses.Fields.Item("PostCode").Value)%>" size="10" maxlength="10" />
      </label></td>
      <td><label>
        [COLOR=red][b]<input type=button class="TextCentre12px" onClick="setOther(); window.close()" value="Add Address">[/b][/color] 
      </label></td>
    </tr>
    <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rsAddresses.MoveNext()
Wend
%>
  </table>
  <p>&nbsp;</p>
</form>
</body>
</html>
<%
rsAddresses.Close()
Set rsAddresses = Nothing
%>

As you can see from the red highlighted text I have created a javascript function called "setOther()" and I am calling this from a button however i am lost as to how to get the info displayed in the appropiate field on the main form.

Any help would be appreciated

Regards

Paul
 
Hi

Use [tt]window.opener[/tt] to reference the... opener window.
Code:
<script type="text/javascript">
function setOther()
{
  if (!window.opener || window.opener.closed) return

  window.opener.document.[green][i]formName[/i][/green].[green][i]fieldName1[/i][/green].value = frmAddress.txtAdd1.value
  window.opener.document.[green][i]formName[/i][/green].[green][i]fieldName2[/i][/green].value = frmAddress.txtAdd2.value
  window.opener.document.[green][i]formName[/i][/green].[green][i]fieldName3[/i][/green].value = frmAddress.txtAdd3.value
  window.opener.document.[green][i]formName[/i][/green].[green][i]fieldName4[/i][/green].value = frmAddress.txtPCode.value
}
</script>
Next time please do not post server-side code. Post the generated HTML as visible through the browser's View source command.

Feherke.
 
Hi feherke,

Thank you for your prompt response and I apolgise for posting the server side code.

I am using the pop up window to display addresses from a database based on certain customers and it my be that I have 1 record or several records and for this reason I have a repeat region on the page.

because of this i cannot get the code to work correctly if there is only 1 record then the values update fine however if there is more than i record i get "undefined" showing in the fields on the main form.

my question is "is what I am trying to do possible given that i may have several records to choose from".

any suggestions would be gratefully recieved.

Regards

Paul

 
Hi people,

OK I am really struggling here, let me try again to explain what I am trying to do.

I have a link that when clicked opens a popup window to show all addresses for a particular customer based on a customer number. I may only have one row and then again I could have 20 rows.

my question is how can I select all data in a particular row and insert it into the correct fields on my main form.

below is the source from the popup window
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SampleAddress</title>
<link href="../Styles/TextStyles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function setOther(){  
if (!window.opener || window.opener.closed) return  
window.opener.document.frmEnquiryGroup.txtSampleAdd1.value = frmAddress.txtAdd1.value;  
window.opener.document.frmEnquiryGroup.txtSampleAdd2.value = frmAddress.txtAdd2.value;  
window.opener.document.frmEnquiryGroup.txtSampleAdd3.value = frmAddress.txtAdd3.value;  
window.opener.document.frmEnquiryGroup.txtSamplePCode.value = frmAddress.txtPCode.value;
}
</script>
</head>

<body>
<form id="frmAddress" name="frmAddress" method="post" action="">
  <table width="90%" border="0" align="center" class="tblbodaSolid">
    <tr>
      <td colspan="5" class="tblHeaderCapsGreen">select address 1</td>
    </tr>
    <tr class="tblHeaderCaps11px">
      <td width="12%">RecId</td>
      <td width="25%">add 1</td>
      <td width="25%">add 2</td>
      <td width="25%">add 3</td>
      <td width="13%">post code</td>
    </tr>
    
    <tr class="TextLeftPlain10px">
      <td>15119</td>
      <td>Oak House
Heyford Close</td>
      <td>Aldermans Green I/E</td>
      <td>United Kingdom</td>
      <td>C11 3BB</td>
      </tr>
    
    <tr class="TextLeftPlain10px">
      <td>19010</td>
      <td>123 My Road</td>
      <td>Somewhere</td>
      <td>United Kingdom</td>
      <td>XX Works</td>
      </tr>
    
  </table>
 <div class="TextCentrePlain10px"><input type=button class="TextCentre12px" onClick="setOther(); window.close()" value="Add Address"></div>
</form>
</body>
</html>
I really would appreciate any help that someone could give me to accomplish what I am trying to do.

Thanking you in anticipation

Regards

Paul
 
OK,

I have abandoned this idea and gone down another route.

feherke, thank you for the input you gave me, I am using it in a different scenario

Regards

Paul

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top