Please note that s13james answer is incomplete in that bind() not a standard function and should be provided elsewhere - one way uses the prototype.js Javascript structure and the other is to do it yourself using the meouw code example.
If you are not using bind() (this is elegant, I have to say), then djangel's answer is what you could do, and this is what I most often do.
source share