mouse coordinates from event

I want to get coordinates from an event object for drawing on an HTML 5 canvas element but am having lots of trouble. I get the event object from the event attribute like this:[code]

[/code]

How do you get the x and y coordinates from an event object?

Below are some functions I tried to use. getOffsetX, getOffsetY take an element in and are supposed to return the positions of them relative to the page but I'm not sure if they work. The getXFromEvent and getYFromEvent are supposed to get the x and y coordinates from an event object. They work somewhat. The pixel coordinates I want to use when drawing on the canvas I'm calculating using getXFromEvent(event)-getOffsetX(canvasElement) and similar for the y.[code] function getOffsetX( el ) { var _x = 0; while( el && !isNaN( el.offsetLeft ) ) { _x += el.offsetLeft - el.scrollLeft; el = el.parentNode; } return _x;}