I try to create a text in canvas by passing the text that will use the fillText()
as the function parameter from a onclick
event in the HTML document, but it tells me that the function crear()
is not defined.
window.addEventListener("load", function(){
/* Dibujo canvas */
var c = document.getElementById("m");
var ctx = c.getContext('2d');
function crear(texto) {
ctx.fillText(texto,55,60);
ctx.fillStyle = "#ECECF9";
}
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<input type="text" id="e" placeHolder="Texto a dibujar.."/>
<input type="button" value="Enviar" onclick="crear(document.getElementById('e').value)"/>
<canvas width="100%" height="100%" id="m"></canvas>
</body>
</html>