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

111
Views
Copy function with clipboard API

i need to copy to clipboard an input text (id=location) from an html form. I am using this code:

const copyToClipboard = str => {
  
  if (navigator && navigator.clipboard && navigator.clipboard.writeText)
    return navigator.clipboard.writeText(str);
  return Promise.reject('The Clipboard API is not available.');
};

From this input:

    <input id="location" type="text" placeholder="Address"/>
    <button onclick="copyToClipboard('location')">Copy</button>

Any ideas? Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are copying to clipboard the world 'location' instead of the input value.

It is possible to access the content of the input using its Id:

document.getElementById("input_id").value;

In your case, to pass the value of the input:

<button onclick="copyToClipboard(document.getElementById('location').value)">Copy</button>
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!