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

144
Views
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 answers
Answer question

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 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!