SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    can you link a variable to a hyperlink using javascript?

    this could be a really daft question - but I will ask it anyway

    I am trying to see if there is a way of using javascript to pass a variable from one page to another when you click on a hyperlink..

    basically I have

    Code:
    <a href="/cgi-bin/simple.pl">simple search</a>
    where I would like to also take across a variable to ensure that anyone getting to the simple search page goes via the perl script.. bit like security as the session is started by simple.pl which then directs you to simplesearch.html if you go directly to simplesearch.html without by passing the perl script a session isn't started and it wont work...

    I think that I am looking for this but using javascript or rather not server side ?

    PHP Code:
    <?= <a href='simple.pl?var=$date' ?>simple search </a>
    any ideas? (and no we cannot use php )

    Thanks

    Sarah
    Regular user

  2. #2
    Posts rarely lloydi's Avatar
    Join Date
    Jan 2002
    Location
    Swindon UK
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, pressed tab then enter by mistake ... see next post
    Last edited by lloydi; Mar 26, 2002 at 06:41.
    Build Your Own Web Site the Right Way!
    A beginners' HTML/CSS book with web standards at its heart
    The Ultimate HTML Reference
    A complete reference, in glorious hardback

  3. #3
    Posts rarely lloydi's Avatar
    Join Date
    Jan 2002
    Location
    Swindon UK
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, this is possible. If the variable is always the same, then you would do almost what you have below:

    <a href="filename.htm?param=something">

    or perhaps you would have

    <script>
    function gohere(param)
    {
    location.href="filename.htm?" + param;
    }
    </script>

    <a href="#" onclick="gohere('something')">

    in the receiving page you'd have to use JavaScript to look at the URL, e.g

    var URL= location.href;
    if (URL.indexOf('something')!=0)
    {
    //do something else
    }
    Build Your Own Web Site the Right Way!
    A beginners' HTML/CSS book with web standards at its heart
    The Ultimate HTML Reference
    A complete reference, in glorious hardback

  4. #4
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks lloydi I certainly didn't expect such an easy answer..

    so using this I could make the parameter the current date and time or something? i.e. a unique number?

    Cheers

    Sarah
    Regular user

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey, Sarah

    Heres a good example that lets you retrieves multiple Querystring values using JavaScript.

    http://www.ghtml.com/pickpocket/getvalues.php


Bookmarks

Posting Permissions

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