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

163
Views
Make an image alt attribute value as a form field value

I want to add the alt value of the image as a form field value. How to do that with JS or Jquery?

Thank you

<img src="x.jpg" alt="grab me" id="ok" />

<form action="/#wpcf7-f1352-o1" method="post" class="wpcf7-form init" novalidate="novalidate" data-status="init">
  
<span class="image-alt"><input type="text" name="iamge-alt" value="" size="40"  aria-invalid="false"></span>

<input type="submit" value="OK" class="wpcf7-submit">
</form>

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

.getAttribute() to grab alt property and then .forms[0] the first <form> and .elements[0] first form control (<input>) to the .value property.

const alt = document.querySelector('img').getAttribute('alt');

document.forms[0].elements[0].value = alt;
<img src="x.jpg" alt="grab me" id="ok" />

<form action="/#wpcf7-f1352-o1" method="post" class="wpcf7-form init" novalidate="novalidate" data-status="init">
  
<span class="image-alt"><input type="text" name="iamge-alt" value="" size="40"  aria-invalid="false"></span>

<input type="submit" value="OK" class="wpcf7-submit">
</form>

about 4 years ago · Santiago Trujillo 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!