How to delete only 1 form field?

Asked

Viewed 173 times

3

I have a bar code entry form of the company’s fiscal notes, which has fields as driver, used car on delivery and etc. So that at the time of entry, the user does not need to fill in the information for each note, I use:

body onload='window.history.back();'

Thus, the form is already filled in with the previous information.

It turns out that the specific field for the barcode also returns filled in, causing users to need to delete it to read the next code.

Does anyone know how I can reload the page only with this field of clean bar code? I’m a beginner in PHP, javascript and such...

Edit:

Follow my form:

<form action="verif_codigo.php" method="POST">

    <!-- Select Motoristas -->

    <select class="form-control" name="motorista">
        <option value="0">Selecione o motorista...</option>
        <option value="1">Opção 1</option>
        <option value="2">Opção 2</option>
        <option value="3">Opção 3</option>

    </select>

    <!-- Select Carros -->

    <select class="form-control" name="carro">
        <option value="0">Selecione o carro...</option>
        <option value="1">Opção 1</option>
        <option value="2">Opção 2</option>
        <option value="3">Opção 3</option>
        <option value="4">Opção 4</option>
    </select>

    <!-- Input Código de Barras -->

    <input class="form-control" type="text" id="codigo" name="codbarras" placeholder="Digite aqui o código de barras da NF-e..."/>


    <input class="form-control btn btn-primary btn-sm" type="submit" value="Gravar"/>
    <input class="form-control btn btn-warning btn-xs" type="reset" value="Limpar"/>

</form>

I have this form, when the user clicks on Submit, the data writes to the database and the form reloads using the body onload I quoted before. Only the form reloads all filled, and I need the field codbarras reload blank, so that the user only reads the next code without having to delete the field.

The best I could do at the moment was use:

onclick="document.getElementById('codigo').value='';" 

In the input country codbarras, only this only erases if you click on the field...

  • Your question is interesting, but it is incomplete to get an answer. Post the form and the javascript code that applies the conditions to it.

4 answers

4


You do not need a script to get the empty field. Add autocomplete="off" in the input from the barcode that the field will always be empty when back to the page:

<input autocomplete="off" class="form-control" type="text" id="codigo" name="codbarras" placeholder="Digite aqui o código de barras da NF-e..."/>

More information about autocomplete you can find at this link.

You can even add the attribute if it is useful, autofocus in the field so that when the page loads the cursor is already in the barcode field ready to receive the information, without having to click on it:

<input autofocus autocomplete="off" class="form-control" type="text" id="codigo" name="codbarras" placeholder="Digite aqui o código de barras da NF-e..."/>
  • Thank you so much dvd, man! It worked perfectly! Thank you all!!

  • @You’re welcome to Guifabri. I updated the answer, maybe even improve the functionality. Abs!

  • Old, even better, now returns the page with the field blank and focused, perfect! Thank you very much!

2

you leave on onload as follows: body onload='window.history.back(); Document.getElementById('codigo'). value='' ';

So you will have two simultaneous functions during loading.

2

One way to do it is by calling the function you want, in case: window.history.back(); into a function when loading the page and then using Java Script, zero the contents of the field. Note that in the example below the element with id = edt, is being initiated in the HTML worthwhile = 7891887261827. When the page is loaded this value is deleted through the function charge(). PS.: Sorry for the lack of good practices leaving the JS along with the HTML, but it’s only for demonstration purposes.

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
    <script type="text/javascript">
    function carregarFormulario() {
        window.history.back();
        var doc = document.getElementById("edt");
        doc.value = "";
    }

    </script>
</head>
<body onload="carregarFormulario();">
<input id="edt" type= text value="7891887261827"/> 
</body>

2

You can place the onload attribute in your barcode field and assign the function to set the null value:

<input onLoad="document.getElementById('codigo').value='';" 
 class="form-control" type="text" id="codigo" 
 name="codbarras" 
 placeholder="Digite aqui o código de barras da NF-e..."/>

Browser other questions tagged

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