I am trying to have an image change when you put in a URL and click a button. But i keep on getting this error:
[object%20HTMLInputElement]:1 GET file:///Users/asbrown/Desktop/MLforSite/[object%20HTMLInputElement] net::ERR_FILE_NOT_FOUND
Here is my code:
$(function() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
function drawimg(image) {
ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, 400, 300);
}
img = new Image();
img.onload = function() {
canvas.width = 400;
canvas.height = 300;
}
img.src = document.getElementById("newURL");
}); // end $(function(){});
body {
background-color: ivory;
}
canvas {
border: 1px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id="canvas" width=100 height=100></canvas>
<form>
<fieldset>
<legend>Input Data for Training</legend>
<p>
<label>Image URL</label>
<input type="text" id="newURL" value="" />
<br>
</p>
<script>
var newURLF = document.getElementById("newURL").innerHTML;
</script>
<input type="button" value="Add to Training Data" onclick=drawimg(newURLF);/>
Does anyone know which part of my code is causing this error? I think it has something to do with the way i used the drawImage() function but i don't know what I am doing wrong. Any help would be appreciated.
img.src=document.getElementById("newURL")->img.src=document.getElementById("newURL").value