...

View Full Version : link code reuse?



Pekka
08-26-2002, 10:15 PM
Hi,

Is there a way to have a Javascript variable printed dynamically into a part of a link so that same snippet of code would be reused accross the page?

Example: I have in html code (from PHP) something like:

<a href="link.php?varlist=a%3A12%3A%7Bi%3A0%3Bs%3A1%3A%220%22%3Bi%3A1%3Bs%3A20%3A%22%22%3Bi%3A2%3Bs%3A4%3A%22 DESC%22%3Bi%3A3%3Bs%3A20%3A%22%3%3A4%3Bs%3A0%3A%22%22%3Bi%3A5%3Bs%3A1%3A%221%22%3Bi%3A6%3Bs%3A6%3A%2 2%22%3Bi%3A7%3Bs%3A1%3A%220%22%3Bi%3A8%3Bs%3A6%3A%22%22%3Bi%3A9%3Bs%3A7%3A%22%22%3Bi%3A10%3Bs%3A1%3A %221%22%3Bi%3A11%3Bs%3A2%3A%2220%22%3B%7D">LINK 1</a>

<a href="link.php?varlist=a%3A12%3A%7Bi%3A0%3Bs%3A1%3A%220%22%3Bi%3A1%3Bs%3A20%3A%22%22%3Bi%3A2%3Bs%3A4%3A%22 DESC%22%3Bi%3A3%3Bs%3A20%3A%22%3%3A4%3Bs%3A0%3A%22%22%3Bi%3A5%3Bs%3A1%3A%221%22%3Bi%3A6%3Bs%3A6%3A%2 2%22%3Bi%3A7%3Bs%3A1%3A%220%22%3Bi%3A8%3Bs%3A6%3A%22%22%3Bi%3A9%3Bs%3A7%3A%22%22%3Bi%3A10%3Bs%3A1%3A %221%22%3Bi%3A11%3Bs%3A2%3A%2220%22%3B%7D">LINK 2</a>

Which I would like to have (in pseudo code):

<a href="link.php?varlist=Javascipt"(printvars())">LINK 1</a>
<a href="link.php?varlist=Javascipt"(printvars())">LINK 2</a>

So that the printvars() would pass the additional link code snippet when user clicks the link. Is this possible? How?

In my application this would save 20-30% of html lenght.

Thanks for any help,

Pekka

beetle
08-26-2002, 10:37 PM
Sure!
<script>
var varlist = "a%3A12%3A%7Bi%3A0%3Bs%3A1%3A%220%22%3Bi%3A1%3Bs%3A20%3A%22%22%3Bi%3A2%3Bs%3A4%3A%22DESC%22%3Bi%3A3%3 Bs%3A20%3A%22%3%3A4%3Bs%3A0%3A%22%22%3Bi%3A5%3Bs%3A1%3A%221%22%3Bi%3A6%3Bs%3A6%3A%22%22%3Bi%3A7%3Bs% 3A1%3A%220%22%3Bi%3A8%3Bs%3A6%3A%22%22%3Bi%3A9%3Bs%3A7%3A%22%22%3Bi%3A10%3Bs%3A1%3A%221%22%3Bi%3A11% 3Bs%3A2%3A%2220%22%3B%7D";</script>

<a href="link.php?" onClick="this.href=this.href+varlist;return true;">LINK 1</a>Or, using the same variable from above...
<a href="javascript:window.location='link.php?'+varlist;">LINK !</a>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum