Forum Moderators: open

Message Too Old, No Replies

I am Trying to pass a JavaScript variable to a URL in a window.open

         

jmaleche

7:19 pm on Jan 1, 2005 (gmt 0)

10+ Year Member



I am trying to pass a JavaScript variable to the
query-string parameter of a URL in a window.open
call. The variable's value is NOT passed just the name of the variable.

The window.open is within a JavaScript function
as is the variable reference.

I can perform an "Alert" and can see the value of the
variable (and it is there and correct) before the code
for the window.open.

Is there a way to pass the value of the JavaScript variable to the query_string of the URL?

My CODE:

print("<script language='JavaScript'>"); TYPE='text/javascript'
print("<!--
function popup(ref_param)
{
var rec_param=ref_param;
alert(rec_param);
window.open('http://www.j-nasa.net/cgi-bin/fullrec.pl?code=rec_param', 'FullRecord',' width=1000,height=650,scrollbars=yes');
}
print //-->");
print("</SCRIPT>");

and the call to this function:

print("<TD WIDTH=95><A HREF='JavaScript:onClick=popup($ecn_ref ) '>$ecn_ref</A></TD> ");

The Perl variable passes just fine and is converted into a JavaScript variable with no errors
BUT the JavaScript variable will not work in the query_string portion of the window.open call.

I can put a Perl variable in query_string portion and it will work fine - which is odd seeing that the URL is part of a JavaScript function and I produce no errors doing this.

RonPK

8:02 pm on Jan 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> window.open('http://www.j-nasa.net/cgi-bin/fullrec.pl?code=rec_param', [..]

Make that
window.open('http://www.j-nasa.net/cgi-bin/fullrec.pl?code=' + rec_param, [..]

Happy new year and welcome to WebmasterWorld!

RonPK

8:06 pm on Jan 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> print("<TD WIDTH=95><A HREF='JavaScript:onClick=popup($ecn_ref )'>$ecn_ref</A></TD> ");

If $ecn_ref is a string, you'll need to quote it:
print("<TD WIDTH=95><A HREF='JavaScript:onClick=popup(\"$ecn_ref\")'>$ecn_ref</A></TD> ");

claus

8:15 pm on Jan 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A couple of things were wrong. Try this:

<script type="text/javascript"> 
function popup(ref_param){
var myString = 'http:\/\/www.j-nasa.net/cgi-bin/fullrec.pl?code=' + ref_param;
alert(myString);
window.open(myString, 'FullRecord', 'width=1000,height=650,scrollbars=yes');
}
</script>

<a href="#" onclick="javascript:popup('$ecn_ref')">$ecn_ref</a>

The most significant error in your code was that you made "rec_param" a hard coded part of the URL of the window you opened.

Looks like RonPK beat me to it :)

jmaleche

6:01 pm on Jan 2, 2005 (gmt 0)

10+ Year Member



This bit of code you provided fixed the whole problem. That was all that was standing in the way of this popup (provides a Mysql lookup call).

I was very frustrated looking for the proper code.

Thank You Both of you for your help