myVar is a global variable, so you don't need to include that in the function definition:
Code:
var myVar='342';
myElement.onpaste = function() {
alert(myVar);
};
Or if you do not want to use global variables, try out function closures:
Code:
function getPasteHandler() {
var handler = arguments[0];
var args = Array.prototype.slice.call(arguments, 1);
return function() {
return handler.apply(this, args);
};
}
myElement.onpaste = getPasteHandler(function(a, b) {
alert(a); // alerts 1
alert(b); // alerts 2
}, 1, 2);
Bookmarks