I have the folowing code :
var canvasData; var canvas2imgval; imageObj1.onload = function() { ctx.drawImage(imageObj1, 0, 0, wdOb1, hgOb1); imageObj2.onload = function() { ctx.drawImage(imageObj2, imgposLeft, imgposTop, wdOb2, hgOb2); //img = c.toDataURL("image/png"); //document.write('<img src="' + img + '" width="256" height="256"/>'); //canvas2img canvasData = c.toDataURL("image/png"); } } console.log("canvasData : "+canvasData ); $("#canvas2img").val(canvasData) ; canvas2imgval = $("#canvas2img").val() ; console.log("canvas2imgval1 : "+canvas2imgval ); The problem is when I view the value of both variables, canvasData is undefined and canvas2imgval1 has no value. I don't know what's wrong with my code. Normally those two variables are marked public with the JavaScript keyword var.
canvasData = c.toDataURL("image/png");What isc?canvas2imgval = $("#canvas2img").val() ;Does that element exist?