Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    link code reuse?

    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%22DESC%22%3Bi%3A3%3Bs%3A20%3A%22%3%3A4%3Bs%3A0%3A%22%22%3Bi%3A5%3Bs%3A1%3A%221%22%3Bi%3A6%3Bs%3A 6%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">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%22DESC%22%3Bi%3A3%3Bs%3A20%3A%22%3%3A4%3Bs%3A0%3A%22%22%3Bi%3A5%3Bs%3A1%3A%221%22%3Bi%3A6%3Bs%3A 6%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">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

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sure!
    Code:
    <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%3Bs%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...
    Code:
    <a href="javascript:window.location='link.php?'+varlist;">LINK !</a>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •