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

142
Vistas
How to I get value from Select Option tag using JavaScript function

I have a dropdown list like this:

<select id="itemsList" onchange="gettingList()">
    <option>Please select the option</option>
    <option value="50">Soap</option>
    <option value="100">Sugar</option>
    <option value="290">Oil</option>
</select>
<br><br>

I have to get the value of the above list in the below input tag.

<input type="text" id="price">

For this, I am using this script.

<script>
    function gettingList() {
        var selectItem = document.getElementById('itemsList').value;
        var displayPrice = selectItem.options[selectItem.selectedIndex].text;
        document.getElementById('price').value = displayPrice;
    }
</script>

How can I resolve this issue.?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can do this:

var selectItem = document.getElementById('itemsList');

function gettingList() {
  document.getElementById('price').value = selectItem.value;
}
<select id="itemsList" onchange="gettingList()">
  <option>Please select the option</option>
  <option value="50">Soap</option>
  <option value="100">Sugar</option>
  <option value="290">Oil</option>
</select>
<br><br>
<input type="text" id="price">

about 4 years ago · Juan Pablo Isaza Denunciar

0

You get the selected price via the select value property. now, you can update the input with it.

    function gettingList() {
    
        var selectItemPrice = document.getElementById('itemsList').value;
        document.getElementById('price').value = selectItemPrice;
    }
<select id="itemsList" onchange="gettingList()">
    <option>Please select the option</option>
    <option value="50">Soap</option>
    <option value="100">Sugar</option>
    <option value="290">Oil</option>
</select>
<br><br>

<input type="text" id="price">

More about the select element - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select

about 4 years ago · Juan Pablo Isaza Denunciar

0

Your function should be like this

function gettingList() {
  let itemsList = document.querySelector('#itemsList');
  let price = itemsList.value
  let item = itemsList.options[itemsList.selectedIndex].text

  document.querySelector("#price").value = price
  document.querySelector("#item").value = item

  console.log(price, item)
}
<select id="itemsList" onchange="gettingList()">
    <option>Please select the option</option>
    <option value="50">Soap</option>
    <option value="100">Sugar</option>
    <option value="290">Oil</option>
</select>

<input placeholder="Price" type="text" id="price">
<input placeholder="Item" type="text" id="item">

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