I have a metro app in WinJS which selects images by using an input file
<body>
<div id="content">
<h1>e-Camera</h1>
<br />
<button id = "imageCaptureButton">Tomar Foto</button>
<input type = "file" id = "uploadCaptureInputFile" accept="image/*" />
<br />
<button id = "uploadCaptureButton">Subir Foto</button>
<br />
<br />
<div id="result"></div>
</div>
</body>
I want to print on my div <div id="result"></div>
inside the result of the picture
this is my javascript file
function getDomElements() {
_imageCaptureButton = document.querySelector("#imageCaptureButton");
_uploadCaptureInputFile = document.querySelector("#uploadCaptureInputFile");
_uploadCaptureButton = document.querySelector("#uploadCaptureButton");
_divPicture = document.querySelector("#result");
}
function wireEventHandlers() {
_uploadCaptureInputFile.addEventListener("change", loadPictureFromFile, false);
}
app.onloaded = function () {
getDomElements();
wireEventHandlers();
_uploadCaptureButton.disabled = true;
}
and the method which is designed for loading the image:
EDIT: thanks to jakerella and several modifications, here it is the anwser:
function loadPictureFromFile(event) {
var selectedFile = event.target.files[0];
var reader = new FileReader();
imageElement = document.createElement("img"); //creates <img id="img"> element
imageElement.title = selectedFile.name; //set photo's name
reader.onload = function (event) {
imageElement.setAttribute("src", event.target.result); //picture's source
_divPicture.appendChild(imageElement); //Add's <img> element to Div element
};
reader.readAsDataURL(selectedFile);
}