Trabajo en javascript básicamente quiero mostrar la imagen cuando el usuario selecciona la imagen del dispositivo la imagen debe cambiar el código que uso en el archivo javascript es
function changeProfile(){ var location = document.getElementById("profileLocation"); alert(location.value); var image = document.getElementById("profileAAImage"); image.src(location.value); }y el código que escribí en el archivo html es
<div class="row"> <div class="col-md-3 form-group" style="padding-left: 7%;"> <img id="profileImage" style="border-radius: 200px;" src="images/interne/areab%20suhaib.jpg" class="img-thumbnail" width="100" height="100" > </div> <div class="col-md-9 form-group mt-3 mt-md-0" style="padding-top: 5%;"> <input type="file" name="file" class="form-control" id="profileLocation" onclick="changeProfile()" onkeyup="changeProfile()" placeholder="select profile image" required> </div> </div>lo que hago para hacer la tarea requerida.
Cambie location.value a location.files[0] para obtener el archivo seleccionado.
function changeProfile() { var location = document.getElementById("profileLocation"); var image = document.getElementById("profileImage"); image.src = window.URL.createObjectURL(location.files[0]); } <div class="row"> <div class="col-md-3 form-group" style="padding-left: 7%;"> <img id="profileImage" style="border-radius: 200px;" src="images/interne/areab%20suhaib.jpg" class="img-thumbnail" width="100" height="100"> </div> <div class="col-md-9 form-group mt-3 mt-md-0" style="padding-top: 5%;"> <input type="file" name="file" class="form-control" id="profileLocation" onchange="changeProfile()" placeholder="select profile image" required> </div> </div>