1
I’m developing a service order registration form for a workshop. I need the registered service to be linked to an already registered customer.
For this I created a search form where the user can search the registered clients and select only one.
In the form I have:
<div class="form-group">
<label>Localize o Cliente</label>
<div class="input-group">
<input type="text" class="form-control" name="cliente" id="cliente" placeholder="Informe o nome do cliente para fazer a busca">
<span class="input-group-btn">
<button class="btn btn-secondary" type="button" id="buscar">Buscar!</button>
</span>
</div>
</div>
<div id="dados">aparece os dados aqui</div>
As demonstrated in div id="data", the data is displayed after a query in the BD. To fetch the data without refresh in the browser I used AJAX.
function buscar(cliente) {
var page = "busca_cliente.php";
$.ajax({
type: 'POST',
dataType: 'html',
url: page,
beforeSend: function () {
$("#dados").html("Carregando...");
},
data: {palavra: cliente},
success: function (msg) {
$("#dados").html(msg)
}
});
}
$("#buscar").click(function (){
buscar($("#cliente").val())
});
The file that brings the data is the search client.php
// claro, antes existem as linhas de conexão e busca, estão funcionando e os dados estão na variável $query
<table class="table" id="tabela">
<tbody>
<tr>
<th>
<i>
Cliente
</i>
</th>
<th>
<i>
Telefone
</i>
</th>
</tr>
<?php
foreach ($query as $linha) {
?>
<tr>
<td id="selecao"> <?php echo $linha->nome ?> </a></td>
<td> <?php echo $linha->telefone . ' ou ' . $linha->celular ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
} else {
echo "Cliente não encontrado";
I need to allow the user to select only one value in that table, when selecting a row the value is displayed in a label, for example the client’s name, and the client’s id is stored in a variable for then I do the Insert in the service table.
I’ve searched the net and I haven’t seen anything like it, if anyone can help me.
Dude, that’s the idea, only in the example you gave me the data are static and in a single file. In my case I have the file with the form for the search. I put the caption that suggested me in this file because that’s where I want the client name to be displayed. I have another file that searches the database and displays the data in a table and this table is called in the form through a javascript function. It turns out that clicking the link in the table is giving a refresh on the page by calling losing the data. If necessary I send you the complete files.
– Rafael Christófano
perfect, that’s right... Now I need to put the link text in an input(id='value') in the form. Would that be? $(Document). getElementById('value'). text($(this).text());
– Rafael Christófano
Of course, getElementById cannot be... :-|
– Rafael Christófano
Let’s go continue this discussion in chat.
– Rafael Christófano