You can use 'this' in event handler:
document.getElementById("preview").onmouseover = function() {
alert(this.id);
}
Or pass event object to handler as follows:
document.getElementById("preview").onmouseover = function(evt) {
alert(evt.target.id);
}
It's recommended to use attachEvent(for IE < 9)/addEventListener(IE9 and other browsers) to attach events. Example above is for brevity.
function myHandler(evt) {
alert(evt.target.id);
}
var el = document.getElementById("preview");
if (el.addEventListener){
el.addEventListener('click', myHandler, false);
} else if (el.attachEvent){
el.attachEvent('onclick', myHandler);
}