0

I'm currently trying to create code which allows the user to pass an image path through a file input box and then change thhe image src to that file using JavaScript. My code tries to accomplish this through getting the file input path, saving that in a variable then getting the element of the picture the user should be able to change and changing the src of that elemant to the file path. However, this doesn't seem to work and returns the alt of the image instead. My code is:

function upload(){
  var fileinput = document.getElementById("image");
  document.getElementById("pic").src=fileinput;
}

The image is:

<img class="profile_pic" id="pic" src="../Images/guitar.jpg" alt="Profile Picture">

and the input html:

`<input type="file" multiple="false" accept="image/* name="image" id="image" class="manage_account_textbox"/><br>
 <button class="upload_image_button" onclick="upload()">Confirm Changes</button> 
Song879
  • 43
  • 9
  • Yes thank you, it's a step in the right direction, my only problem with it is that it runs the code automatically and doesn't wait till my button is clicked. – Song879 Apr 24 '20 at 11:12
  • 1
    Just change the event / function which triggers it, then. – ADyson Apr 24 '20 at 15:48

0 Answers0