-1
I’m having a problem that I can’t solve, I’m building a library inventory system, and I’m using a reader to read the barcodes from the books, but after I use the reader to pick up the code and search the bank, the field is not clean, but when I add the code
$(document).keypress(function(e) { if(e.which == 13) $('#btn-search').click(); document.getElementById('input-search').value=''; });
The field is clean, but as the reader of an enter after reading, the search parameter goes blank and then the system makes a query in the database with empty parameter, follows the code.
Search.php `
search($search) Book not registered in the database... Search data: <table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th>Titulo</th>
<th>Codigo de Barras</th>
<th>Biblioteca</th>
</tr>
</thead>
<tbody>
<?php foreach($user->search($search) as $row): ?>
<tr>
<td><?php echo $row->tituloexemplar; ?></td>
<td><?php echo $row->codigobarra;?></td>
<td><?php echo $row->nomebiblioteca; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
`
php search.
`
Inventory
Research
<!-- script -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="js/usuarios.js"></script>
<script>
$(document).keypress(function(e) {
if(e.which == 13) $('#btn-search').click();
document.getElementById('input-search').value='';
});
</script>
`
Opa Lindomar, thank you for the answer, but still fall into the same dilemma, the input-search field, after reading in the reader he does not clean the field, then when I try to read another book, the field remains filled, I would need that every time a query is made in the bank, the input-search field was cleared, but without executing an action, until you read the next code.
– Relton Charles
change Document.getElementById('input-search'). value=''; by $('#input-search'). val('')
– Lindomar
Tested the code? It clears the input-search field after the query, just needs to adapt to your need
– Lindomar
I did the test, but when I do the process it fills in the second input, and in the first it looks for all the bank results, maybe the problem is my javascript, but I could not identify what is wrong.
– Relton Charles
$(Document). ready(Function() { // Search the database while holding down the $("#btn-search").click(Function() { var search = $("#input-display").val(); search(search); }); Function search(value) { $.ajax({ type: 'POST', dataType: 'html', url: 'fetch.php', beforeSend: Function() { $("#data").html("Loading..."); }, date: {value: value}, Success: Function (result) { $("#data").html(result); } }); } });
– Relton Charles
Lindomar, I made a change here in js and it worked, thank you very much.
– Relton Charles