Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda