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

Can't get popup Window to call function in parent

Status
Not open for further replies.

Loyd5

Technical User
Jul 16, 2005
3
0
0
US
I would really appreciate some help on this. I think I have most of it right but for some reason it's not quite right. I think the problem is that I don't have the code right where the popup window calls the function in the parent window. Here is my code so far:

JAVASCRIPT ON PARENT PAGE:
var NewEmailImg;
function ChangeImage(img) {
alert("from functions.asp, ChangeImage function start");
NewEmailImg=img;
alert("from functions.asp, NewEmailImg = " + NewEmailImg);
}

function Change() {
alert("from functions.asp, Change function start");
emailIcon.src=' alert("from functions.asp, Change function end");
}

IMAGE AND LINK CODE (rs(eCount) comes from a db query):
<a href="#" onClick="alert('from setEmailIcon.asp, onClick event start'); ChangeImage(this);
openPopWin('emailResponseUpgrade.asp?ID=<%=rs("cid")%>&uID=<%=rs("urpID")%>&pID=<%=pID%>&pg=<%=pqs%>',
575, 465, 'scrollbars', 20, 20); alert('from setEmailIcon.asp, onClick event end');">
<% If rs("eCount") <> 0 then %>
<img id="emailIcon" name="emailicon" border="0" src="images/emailIcon.jpg" width="26" height="30">
<% Else %>
<img id="emailIcon" name="emailicon" border="0" src="images/emailIcon2.jpg" width="32" height="30">
<% End if %>
</a>

JAVASCRIPT IN POPUP WINDOW:
function changeEmailIcon() {
alert("from eTxtBox.asp, changeEmailIcon function start");
parent.window.opener.document.Change();
alert("from eTxtBox.asp, changeEmailIcon function end");
}

CALLING CODE IN POPUP WINDOW:
<input type="button" value="Send Email Message" onClick="alert('from eTxtBox.asp, submit button click');
changeEmailIcon();">

I all the alerts popup on schedule until it gets to the action line, parent.window.opener.document.Change(). the alert just before that line works, but the action line doesn't make the image change and the alert right after that doesn't show.

There isn't an error thrown, and I've tried several other calls, like window.opener.Change(), parent.parent.window.opener.document.change(), but nothing seems to work. Can anyone tell what I'm missing?

Thanks,

Loyd Campbell
 
Have you tried it in Firefox and checked the error console?

Lee
 
What is the [tt][maroon]openPopWin[/maroon][/tt] function? A custom function? And how do you open the popup window?

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
If he uses Firefox's error console, he'll find that and most other errors.

Lee
 
[1] This is needed for cross-browser.
>emailIcon.src='[ignore][/ignore]';
[tt]document.getElementById("emailIcon").src='[ignore][/ignore]';[/tt]

[2] There is no cause for experimental science at this spot: No "document" reference, period. (parent is not needed, only if you like to do so; I prefer not.)
>parent.window.opener.document.Change();
[tt]window.opener.document.Change();[/tt]

[3] This is a long a tag with img embedded in it.
><a href="#" onClick="alert('from setEmailIcon.asp, onClick event start'); ChangeImage([red]this[/red]);
openPopWin('emailResponseUpgrade.asp?ID=<%=rs("cid")%>&uID=<%=rs("urpID")%>&pID=<%=pID%>&pg=<%=pqs%>',
575, 465, 'scrollbars', 20, 20); alert('from setEmailIcon.asp, onClick event end');">


The part marked red is not quite correct. It corrects itself only href is default to it. There is another sense of its incorrectness. It is that you probably want to get the img's src to store it in the global variable NewEmailImg.

[tt]<a href="#" onClick="alert('from setEmailIcon.asp, onClick event start'); ChangeImage(this[red].getElementsByTagName('img')[0].src[/red]);
openPopWin('emailResponseUpgrade.asp?ID=<%=rs("cid")%>&uID=<%=rs("urpID")%>&pID=<%=pID%>&pg=<%=pqs%>',
575, 465, 'scrollbars', 20, 20); alert('from setEmailIcon.asp, onClick event end');">[/tt]

You can of course use again document.getElementById() to get to img emailIcon. The above is more precise in the sense of restricting to the img embedded within the a tag.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top