Can you link a variable to a hyperlink using javascript?

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

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

<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… :dodgy:

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

<?= <a href='simple.pl?var=$date' ?>simple search </a>

any ideas? (and no we cannot use php :D)

Thanks

Sarah

Oops, pressed tab then enter by mistake … see next post

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
}

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

hey, Sarah

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

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