Column selection and URL modification
&lt;script type=&quot;text/javascript&quot;&gt;
$(function () {
    var $lastSelected = $([]);
    $('tr').click(function () { //tr tag is always inside a table
        $lastSelected.removeClass('selected'); //by caching this variable in the closure we don't need to traverse for it again
        $lastSelected = $(this).addClass('selected');
    });

    $('.image_bar a').click(function (e) { 
        var url = $(this).attr('href').split('var'), //both checks if var is there and prepares for the replacement
            name;
        if ($lastSelected.length === 0) {
            return url.length==1; //any urls that do not have var in them will still work
        }

        name = $lastSelected.children().eq(2).html();
        window.location = url.join(name);
    });
});
&lt;/script&gt;

Here I am assuming your toolbar is outside of your table.
About the changes:

$(function () { lets you move this script tag elsewhere in your document (perhaps to an external script)
By caching $lastSelected, fewer DOM traversals need to happen.
Knowing $lastSelected enables moving the $.fn.each call out of the tr click event by setting name inside of it.
Since the .each call is no longer in the click event, it can be a click event of its own (no more need to iterate over it).
Instead of modifying the a tags we can just set window.location since we are now in the event where the user has clicked.
Finally, if a row is not selected up front, the $lastSelected variable will not provide a valid name. Thus we shouldn't allow the link to be clicked if it contains var (done by the return statement).