Click to See Complete Forum and Search --> : Passing Varibles to a Popup Window Function


trbates
07-19-2003, 10:44 AM
I am trying to use a single popup window function for multiple images on a site I am working on. Currently, I am trying to pass a variable for both width and height when calling the function. The function is recieving the correct value, however when using the variable it does not work. My code is as follows...

***The Popup Window Function...

<script language="JavaScript">
<!-- Hide the script from old browsers --
function OpenPage(page,picwidth,picheight) {
var NewWindow=open('','popup','menubar=0,toolbar=0,location=0,directories=0,scrollbars=0,resizable=0,sta tus=0,width=picwidth,height=picheight, screenX=1, sreenY=1, top=1, left=1');
NewWindow.focus();
window.open(page,target="popup");
}
// -->
</SCRIPT>


***The method I am using to call the Function

<a href="javascript:OpenPage('/finishedtrucks/red1.html','500','323')"><img src="/images/red1s.jpg" border="1" height="120" width="200"></a>



The problem appears to be that the window.open does not "see" what picwidth/picheight are supposed to be ... even though they are correct in the function. (tested with a quick alert box and the number was correct)

Any help would be greatly appreciated :)

Thanks in Advance

Travis

David Harrison
07-19-2003, 10:59 AM
Try this on for size:

Edit: Oops, didn't spot that, attachment re-uploaded.

Khalid Ali
07-19-2003, 11:01 AM
Originally posted by trbates

The problem appears to be that the window.open does not "see" what picwidth/picheight are supposed to be ...
Thanks in Advance

Travis
Yes the reasone is you are using wront syntax to do that...Javascript does not automatically figure out that you are trying to pass it a variable,you have tell it that a certain value is to be retrieved from a variable.. this code here

width=picwidth,height=picheight,
would work if it were not in a string
to make it work you have to do something liket his

"width="+picwidth+",height="+picheight+",....

trbates
07-19-2003, 02:15 PM
Thank you very much for the quick reply.

However, I changed it to ...

...,width="+picwidth+",height="+picheight+",....

Any ideas as to why it still wont work?

BTW, I can post all of the code if that would help ... just didnt want unnecessary clutter :)

Thanks again for the help Thus Far

Travis

trbates
07-19-2003, 02:19 PM
I was using " instead of ' in the function ... thanks Lavalamp for pointing that out :)

It works like a charm now ... thanks for the help

Travis

David Harrison
07-19-2003, 03:20 PM
erm... Happy to help. :)