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

203
Views
Why I am getting Undefined Value when I click on image ? How to fix this?

I am getting this error (undefined) when I am clicking on image to get the value of image. Can you please explain the reason behind it and how to get and pass the value to onclick function in this case.

      <div id="fi" value="0">
        <img src="first.JPG" alt="first" id="first" value="01" onclick="checkingg(this.value)"/>
      </div>

      // inside script tag
      function checking(img_val) {
        console.log(img_val);
      }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No problem in your approach, except value is not a valid attribute on image and hence will be undefined. Use custom data attributes data-*:

      function checking(img_val) {
        console.log(img_val);
      }
  <div id="fi" value="0">
        <img src="https://media.istockphoto.com/photos/analyzing-samples-in-test-tube-backgrounds-picture-id1290116527?b=1&k=20&m=1290116527&s=170667a&w=0&h=51bfejWaiLIK8ZeeP7u7q0b1UINUwx3dbH86HZNNuPA=" alt="first" id="first" data-value="01" onclick="checking(this.dataset.value)"/>
      </div>

about 4 years ago · Juan Pablo Isaza Report
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!