I'm not sure what you're trying to achieve here but if you just want to have an image on the page, don't use the 'canvas' and change the image via the 'src' property.
However, if you want to have this on a canvas - which I suspect - you have to store the coordinates/dimensions of the image when it is drawn. Then, to change the picture, use 'clearRect()' to blank that area and draw the new image.
Note that in your code, the 'img' is not passed to the canvas as an element, but as a bitmap, as mentioned by 'Simon Sarris'. That means, your handler for the 'onclick' event must be assigned to the canvas. Then check whether the click occourred within the borders of the image. to achieve that, you need to access 'clientX' and 'clientY' from the event object which declare the position of the mouse click relative to the client area. Make sure to keep your img coordinates relative to the client area too.
Javascript:
window.onload = init;
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var img = new Image();
function init(){
img.src = 'Birthday.jpg';
context.drawImage(img, /* your img coords */ );
canvas.addEventListener('click', onCanvasClick);
}
function onCanvasClick(event){
var clickX = event.clientX;
var clickY = event.clientY;
if ( clickX > imgLeft && clickX < imgRight && clickY > imgTop && clickY < imgBottom ){ changePicture(); }
}
function changePicture(){
context.clearRect( /* your img coords */ );
img.src = /* new img URL */;
// save new img coords before next step
context.drawImage(img, /* your new img coords */ );
}
Image coordinates called 'imgLeft', 'ImgRight', 'ImgTop', 'imgBottom' / relative to client area!
You may have to modify the function name in 'addEventListener()', I'm not entirely sure. Maybe put the following:
canvas.addEventListener('click', function(){ onCanvasClick(); });