Click to See Complete Forum and Search --> : inserting javascript value into a url


ddurose
03-25-2003, 01:49 PM
When the html pages loads, I have a javascript function located in between the HEAD tags that retrieves a value from a cookie stored on the user's computer. I need to have that value inserted into a hyperlink url. Here is my current link code:

<a href="#" onClick="window.open('http://www.someurl.com','window','scrollbars=yes,toolbar=no,directo
ries=no,width=752,height=550')">

I need to have the javascript value somehow inserted in after the http://www.someurl.com text (i.e. http://www.someurl.com?jsvalue=blah). I'm not sure how this can be done in javascript. I need to know how to print out JavaScript variable values by themselves in the body of an html document. I know how to insert the value into a hidden form input field:

<script>
document.write("<input type=hidden name=custom value="+affiliatecookie+">");
</script>

BUT, I need to get the value inserted into a url located in a hyperlink. Any ideas? Thanks in advance.

Phil Karras
03-25-2003, 02:04 PM
Sure, something like this should work: (NOTE the alert statement at the end so you can see what it all looks like before you trust it.)

<script language="JavaScript" type="text/javascript"> <!--

var Val = '123.45';
var MyLink = "<a href='#' onClick=";
MyLink += '"window.open(';

MyLink += "'http://www.someurl.com?Val="+Val+"', ";

MyLink += "'window','scrollbars=";
MyLink += "yes,toolbar=no,directories=no,width=752,";
MyLink += "height=550')";
MyLink += '">';

alert("MyLink = "+MyLink); // TEST it!

// -->
</script>

You don't have to do it this way but I find breaking something that long up so I can mix & match the quotes correctly is much easier to SEE and with the help of an alert before I actually use it, I can see what the command looks like to be sure it's OK.