Question: as the above stated, I wish to make once user click the hyperlink and it should copy into a variable in PHP. Is it possible to do it?

This is what I have tried but nothing seems to come out?

**Code:**

```
    <script type="text/javascript">
    function getdl(){
        var dlink = (document.getElementById('getdllink').getAttribute('onclick'))
         <? $url ?> = var dlink
    }
    </script>

<a id="getdllink" onclick="getdl()" href="#"><strong>Master Prospectus</strong></a></font>
            <? echo $url; ?>

```

I did something wrong? Please help. Thanks!

Answer: 
Yes, you did it wrong. PHP is server-side so, it's executed before the client-side. This means that you can't directly assign javascript variable to php variable because it has already been interpreted. You have to send it using ajax.

Here's sample:

```
var http = new XMLHttpRequest();
var myVar = 'myValue';
http.onreadystatechange=function(){
    if (http.readyState==4 && http.status==200){
        //Do whatever you want with respnse you'll get in http.responseText
        //http.responseText will contain text what php will print. In this
        //example value of myVar.
    }
}
http.open("GET","yourScript.php?myvar=" + myVar);
http.send();

```

On PHP side you can do:

```
echo $_GET['myvar'];

```
Here is how to do it without AJAX or PHP...

```
<script type="text/javascript">
function getdl(){
    var dlink = (document.getElementById('getdllink').getAttribute('href'))
    document.getElementById('dest').innerHTML = dlink
    return false
}
</script>

<a id="getdllink" onclick="return (getdl())" href="http://www.google.com"><strong>Master Prospectus</strong></a><br />

<span id="dest"></span>

```