popup window: Return value to correct text box?

M

Mel

Hi! I have two text boxes and two image buttons. When I click image
button 1 or 2 the same popup window is displayed (using 'window.open'
method). When I click image button 1 the returning data from the
popup window is placed in text box 1 on the parent form. When I click
image button 2 the returning data is placed in text box 1 also. It
should be placed into text box #2 on the parent form. How do I change
my javascript code so the data appears in the correct text box?

(using javascript, asp.net 2.0, vb.net)
 
G

Guest

before calling window.open, set a global var to the textbox to update. then
in the popup, reference the global variable instead of the hardcoded textbox

-- bruce (sqlwork.com)
 
M

Mel

before calling window.open, set a global var to the textbox to update. then
in the popup, reference the global variable instead of the hardcoded textbox

-- bruce (sqlwork.com)

I am not sure how to do this in javascript. Here is my code:

POPUP WINDOW (ASPX):
<script language="javascript" type="text/javascript">
function Done()
{
var Angle=document.getElementById('txtAng').value;
var ret= new Array(Angle);
window.opener.update(ret);
window.close();
}
</script>
<asp:TextBox ID="txtAng" runat="server" Width="48px"
BackColor="LemonChiffon" TabIndex="7" AutoPostBack="True"></
asp:TextBox> 'I want to store txtAng.Text value on popup window to
txtAng<#>.Text on parent window.
<input id="cmdDone" type="button" onclick="Done();" value="Done"
tabindex="9" style="width:128px"/></td>

PARENT WINDOW (ASPX.VB file)
OpenPopUp(imgAng1, "AngleCalc.aspx", "", 420, 250) 'OpenPopUp
subroutine just calls window.open method. I just pass page name,
window height, width, etc.
OpenPopUp(imgAng2, "AngleCalc.aspx", "", 420, 250)

PARENT WINDOW (ASPX file)
<script language="javascript" type="text/javascript">
function update(elemValue)
{
document.getElementById;
document.getElementById('<%=txtAng1.ClientID
%>').innerText=elemValue[0]; 'This always stores to txtAng1.Text.
How do I pass the text box index to here?
}
</script>
<asp:TextBox AutoPostBack="True" BackColor="Black" Font-
Names="Verdana" Font-Size="Small" ForeColor="White" ID="txtAng1"
OnTextChanged="txtAng1_TextChanged" runat="server" TabIndex="15"
Width="49px"/>
<asp:ImageButton ID="imgAng1" runat="server" ImageUrl="~/Images/
Ang.bmp" />
 
M

Mel

before calling window.open, set a global var to the textbox to update. then
in the popup, reference the global variable instead of the hardcoded textbox

-- bruce (sqlwork.com)

I am not sure how to implement that in javascript. Here is my code:

Parent Page_Load (aspx.vb file)
OpenPopUp(imgAng1, "AngleCalc.aspx", "", 420, 250) 'calls
window.open (passes page name, height, width, etc.)
OpenPopUp(imgAng2, "AngleCalc.aspx", "", 420, 250)

Parent javascript (aspx file)
<script language="javascript" type="text/javascript">
function update(elemValue)
{
document.getElementById;
document.getElementById('<%=txtAng1.ClientID
%>').innerText=elemValue[0]; 'writes to text box #1 all the time
}
</script>

Popup window javascript (aspx file)
<script language="javascript" type="text/javascript">
function Done()
{
var Angle=document.getElementById('txtAng').value; 'txtAng is a
text box on my popup window that I want to pass to txtAng<#>.Text in
my parent window
var ret= new Array(Angle);
window.opener.update(ret);
window.close();
}
</script>
 
M

Mel

before calling window.open, set a global var to the textbox to update. then
in the popup, reference the global variable instead of the hardcoded textbox
-- bruce (sqlwork.com)

I am not sure how to implement that in javascript. Here is my code:

Parent Page_Load (aspx.vb file)
OpenPopUp(imgAng1, "AngleCalc.aspx", "", 420, 250) 'calls
window.open (passes page name, height, width, etc.)
OpenPopUp(imgAng2, "AngleCalc.aspx", "", 420, 250)

Parent javascript (aspx file)
<script language="javascript" type="text/javascript">
function update(elemValue)
{
document.getElementById;
document.getElementById('<%=txtAng1.ClientID
%>').innerText=elemValue[0]; 'writes to text box #1 all the time
}
</script>

Popup window javascript (aspx file)
<script language="javascript" type="text/javascript">
function Done()
{
var Angle=document.getElementById('txtAng').value; 'txtAng is a
text box on my popup window that I want to pass to txtAng<#>.Text in
my parent window
var ret= new Array(Angle);
window.opener.update(ret);
window.close();
}
</script>

Okay, I finally figured it out. I added an OnClientClick method.
When a user clicks on an image button it calls a javascript function
which sets global variable and this variable is used in a select case
statement in my update function.

Anyone know why my javascript code does not work in Firefox? The
popup window appears but the data is not returned to the parent
window. I have javascript turned on in my Firefox settings and I am
not getting an error in the "Error Console".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top