I'd take that a slightly different way if I were you. Change the text link when the page loads, not on the click. I'll give the example in jQuery, but it could easily be done in vanilla javascript (though, jQuery is nicer)
$(function() {
$('a[href$="url="]') // all links whose href ends in "url="
.each(function(i, el) {
this.href += escape(document.location.href);
})
;
});
and write your HTML like this:
<a href="http://example.com/submit.php?url=">...</a>
the benefits of this are that people can see what they're clicking on (the href is already set), and it removes the javascript from your HTML.
All this said, it looks like you're using PHP... why not add it in server-side?