How do I program an insert image button? [duplicate]

-1

I want a "Insert Image" button and when I click on it, the image inserted will appear on the image (taken from the pc), you do not need to save the information or anything, just make the image appear on top. >     

asked by anonymous 15.09.2018 / 16:53

1 answer

0

Hello, good morning, there goes the complete code ... Good luck!

<html>
<head>
<title>Default</title>
</head>
<body>
<div style="width:350px;height:350px;border:dashed 1px #ccc;" id="view_photo"><img id='output' style="height:100px; width=100px"></div>
<input type="file" name="files" />

<!--[Script]-->
<script>
var files = document.querySelector('input[name="files"]');

files.addEventListener("change", function(file){
	var input = file.target;
	
	var reader = new FileReader();
    
	reader.onload = function(){
      var dataURL = reader.result;
      var output = document.getElementById('output');
      output.src = dataURL;
    };

    reader.readAsDataURL(input.files[0]);
});
</script>
</body>
    
16.09.2018 / 08:43