First of all, if you're using $HTTP_REFERER in PHP to validate something for security, you should be aware that this isn't always as secure as you may think. The dependency on whether or not a referer variable is sent to the server relies on the browser, and not all browsers will send it....you have been warned 😃
As for the Jscript...sorry, the only way you can have a Javascript link properly send a referer variable to the server is if you have that javascript interact with another element in that page that actually sends the request (such as a form).
For example:
<a href="#" onClick="javascript:document.location='page.php'">This Link won't work</a>
<form name="theForm" action="page.php" method="get">
</form>
<a href="javascript:document.theForm.submit()">This link will work</a> (and it will send a referer variable to the server)