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

150
Vistas
Detect as soon as the input field is populated through barcode scanner

I have two input fields productName and quantity, productName field is getting populated using a barcode scanner(don't have access to code), my requirement is to detect as soon as the value gets populated in productName fields so that I can parse the value and populate the second field quantity.

<input type="text" id="productName" name="productName">
<input type="text" id="quantity" name="quantity">

Since I don't have access to code that scans the barcode and populate the productName field, there is one possibility which I think of is repeatedly checking if the field has value or not like below

myVar = setInterval(checkValue, 1000);

function checkValue(){
var productName= document.getElementById("productName");
console.log("running");
if (productName && productName.value) {
  document.getElementById("quantity").value=productName.value;
  clearInterval(myVar);
}
}

But I am looking for a better approach in vanilla Javascript, is there an alternate solution?

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

0

You can use onchange.

Example:

const productNameField = document.querySelector('#productName');
const quantityField = document.querySelector('#quantity');

const populateQuantityField = () => {
  quantityField.value = productNameField.value;
}

productNameField.addEventListener('change', populateQuantityField);

Further Reading:

  • https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event
  • https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onchange
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