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

148
Vistas
How to clear the value of an input if there is no results or if it has a null value?

I am trying to clear the value of an input depending if it finds or not an id, if it finds an existing id, js updates the value of an input, but if it doesn't it keeps the last one found but I need to have the value clear, can someone tell me what is wrong:

function driverdata(valueid)
{
    var numero_id = valueid;
    //console.log(valueid)
    var idselect = document.getElementById('driver'+id_number).value;
    document.getElementById("idinsearch"+ id_number).value = idselect;
    //console.log(idselect);
    var placa = document.getElementById("searchable"+idselect).value;
    console.log(placa);
    if (placa != null) {
        document.getElementById("placa"+ id_number).value = placa;
    } else {
        document.getElementById("placa"+ id_number).value = "";
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In the method driverdata you don't define variable id_number so it's undefined when you try get element by id

So if id_number is equal to the parameter of the method you can directly use it

moreover to clear value you are right it's elem.value = ""

withour yout html i can propose you the following one => your script run

function driverdata(numberId)
{
    var idselect = document.getElementById('driver'+numberId).value;
    document.getElementById("idinsearch"+ numberId).value = idselect;
    var placa = document.getElementById("searchable"+idselect).value;
    if (placa != null) {
        document.getElementById("placa"+ numberId).value = placa;
    } else {
        document.getElementById("placa"+ numberId).value = "";
    }
}
<div onclick="driverdata(1)">
click me<br/>
 driver<input id="driver1" value="1"/><br/>
  idinsearch<input id="idinsearch1"/><br/>
  <div id="searchable1">
    input that will be clear <input id="placa1" value="test"/>
  </div>
</div>

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