Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
How do I create an <img> tag that javascript can modify?

I want to write a simple html page where there is an img tag and an input tag.

I am trying to write the javascript that will read the users image file selection and change or add the 'src' in the img tag to show the users image without uploading it to a server.

This isn't working and I cannot figure it out:

<input type="file" id="file">
<img id="user_img" src="user_img">

<script  type="text\javascript" >
const user_img = document.querySelector('#img')
document.querySelector('#file').addEventListener('input', event => {
  if (event.target.files.length === 0) {
    console.error('No file provided')
    return
  }
  const reader = new FileReader()
  reader.addEventListener('loadend', () => {
    user_img.src = reader.result
  })
  reader.readAsDataURL(event.target.files[0])
})
</script>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!