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

249
Views
Adding Additional information to dropdown box options

I am wanting to add hidden/additional information to a dropdown box. Currently, it works using

javascript

function myFunction() {
  var copyText1 = document.getElementById("ID");
  

  var value = copyText1.value;
  navigator.clipboard.writeText(value);

}  

and html

<select id="ID">
     <option>Call James</option>
     <option>Call Bob</option>
     <option>Call Jane</option>
</select>


<button onclick="myFunction()">Copy number</button>

however, I would like when 'Call James' is selected, the copy number will copy a phone number (eg - '5551234') to the clipboard instead of the text 'Call James'

Any assistance would be much appreciated.

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

0

  • Use the Element's value attribute to store and then retrieve the number
  • Stop using inline on* handlers. Use Element.addEventListener instead.
  • Use type="button" since buttons are by default of type Submit.
const elSelect = document.querySelector("#ID");
const elCopy = document.querySelector("#copy");

const copyNUmber = () => {
  console.log(elSelect.value);
  navigator.clipboard.writeText(elSelect.value);
};

elCopy.addEventListener("click", copyNUmber);
<select id="ID">
  <option value="123456000">Call James</option>
  <option value="654321000">Call Bob</option>
  <option value="999999000">Call Jane</option>
</select>

<button id="copy" type="button">Copy number</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!