Easy, just read the attribute, encode with encodeURIComponent, and concatenate the value into the string.
$('#container').click(function(event){
event.preventDefault();
var variable = $(this).attr('value');
$.post('/cart.php?mode=add&productid=' + encodeURIComponent(variable) + '&amount=1&redirect_from_cart=Y', function(response){
alert(response);
});
});
The a tag does not normally have a value attribute however, so I would recommend using a data attribute instead to keep the HTML nice and valid.
<a id="container" data-value="{$variable}" href="#">Click This</a>
$('#container').click(function(event){
event.preventDefault();
var variable = $(this).attr('data-value');
$.post('/cart.php?mode=add&productid=' + encodeURIComponent(variable) + '&amount=1&redirect_from_cart=Y', function(response){
alert(response);
});
});