Clear field after X time

Asked

Viewed 226 times

3

I have the form below, that after 2 minutes it updates every page:

inserir a descrição da imagem aqui

With the command below:

<meta HTTP-EQUIV="refresh" CONTENT="120;URL=http://pcn-sig.peccin.local/cracha">

And with that he resets the form on each access:

<body class="noheader" onload="moveRelogio(); getInfo(); document.cadastro.reset()">

But I’m having a problem, because the machines given to this application are very slow, K6 2 500 down, and in some the page takes 5 to 10 seconds to open, and here where I tested it does not take 1 second. How could I "clear" only the badge field instead of every page?

Excerpt from the form:

          <form id="cadastro" name="cadastro" method="POST" action="adicionaBatida.php" autocomplete="off">
            <table cellspacing="0">

              <tr>
                  <td>Data:</td>
                  <td><input type = "text" style="font-family: Verdana, Geneva, sans-serif; height: 40px; font-size: 30px;" readonly="true" id="data_inicio" name = "data_inicio" size = 12 maxlength =10  value= "<? echo date('d-m-Y');?>" ></td>
              </tr>
              
              <tr>
                  <td>Hora Atual:</td>
                  <td><input type = "text" style="font-family: Verdana, Geneva, sans-serif; height: 40px; font-size: 30px;" readonly="true" id="hora_inicio" name = "hora_inicio" size = 12></td>
              </tr>

              <tr>
                 <td>Crachá: </td>
                 <td><input type = "password" name="cracha" id="cracha" placeholder="Passe o crachá..." size = 15 maxlength = 10 onChange="getDados();" onkeyup="troca_campo(this)"  onkeypress="return SomenteNumero(event)" autofocus></td>
              </tr>


              <? // EXIBE O NOME ?>
              <tr>
                 <td></td>
                 <td><textarea cols="25" rows="10" wrap="hard" style="font-family: Verdana, Geneva, sans-serif; height: 80px; font-size: 30px;" id="nome" name="nome" placeholder="Aguardando crachá..." size="35" readonly="true"></textarea></td>
               </tr>

  • You should clear the independent field if you have something on it or not?

  • Hello Diego, post the code of your form

  • @Randrade, yes, because some joker can type on the numeric keyboard and leave, or pass the badge without confirming, then the field is filled and the next person has no way to pass. Thomas Lima will edit the question.

1 answer

3


function LimpaCracha(){
    document.getElementById('cracha').value = '';
}

setInterval(function(){
    LimpaCracha();
}, 10 * 1000);

where 10 is the number of seconds.

Cleans every 10 seconds.

  • 1

    I was doing the fiddle while you answered. So I’ll just leave your answer and post the fiddle here.

  • Exactly! But I noticed that it runs only once. It has to be "constant" to call the function?

  • 1

    @Diego look at the example I added. It’s almost the same code as the one he posted.

  • 1

    This @Diego. Use the Randrade script.

  • Thanks @Zoom and Randrade, it worked. That’s exactly what I needed.

  • 1

    Half the points should be for @Randrade.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.