How do I delete only 1 form field?

3

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

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

In this way, the form is already filled in with the previous information.

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

Does anyone know how I can reload the page only with this clean barcode field? I am new to 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 submit, the data is written to the database and the form reloads using the body onload I mentioned earlier. But the form reloads all filled up, and I need the codbarras field to reload blank, so that the user only reads the next code without having to delete the field.

The best I've achieved so far was to use:

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

No input of field codbarras , except that this only goes away if you click on the field ...

    
asked by anonymous 17.01.2018 / 12:54

4 answers

4

You do not need a script to get the field empty. Add autocomplete="off" to input of the barcode that the field will always be empty when you return 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 finds in this link .

You can even add the attribute, if useful, autofocus in the field so that when the page loads the cursor is already in the bar code 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..."/>
    
17.01.2018 / 13:47
2

You leave in onLoad as follows: body onload = 'window.history.back (); document.getElementById ('code'). value = '' ';

So you have two simultaneous functions while loading.

    
17.01.2018 / 13:34
2

One way to do this is to call the function you want, in the case: window.history.back (); inside a function when loading the page and then using Java Script , clear the contents of the field. Note that in the example below the element with id = edt, is starting in HTML with value = 7891887261827 . When the page loads, this value will be erased using the loadForm () function. PS: Sorry for the lack of good practices leaving JS together with HTML, but it is 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>

    
17.01.2018 / 13:39
2

You can put 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..."/>
    
17.01.2018 / 13:42