I have a form where there is an input'search '; that at the time of writing the name, it finds the coincidences and displays the information of the possible clients that I am looking for. the matter begins that when selecting the row I have to capture the data of the cells of the same row OR of another row and send it to some inputs and save the information. I just have to capture a row with the 'td' of the row, not several rows with their 'td'. Because of the situation, a client can have several addresses. I leave the code. Thank you very much.
<!--input search Html-->
<input type="type" name="busqueda" id="busqueda" class="form-control" placeholder="Buscar cliente...">
<br>
<br>
<table class="table table-hover" id="tabla"><!--Tabla-->
<div id="tabla_resultado"><!--Tabla donde se despliega tr ytd-->
</div>
</table>
<br>
<input id="nombre">
<!--Fnn html -->
$tabla.=
'
<thead class="table-dark">
<tr>
<td>N°</td>
<td>Nombre</td>
<td>Apellido</td>
<td>Empresa</td>
<td>Colonia</td>
<td>Direccion</td>
<td>Razon Social</td>
</tr>
</thead>
';
while($fila = mysqli_fetch_array($query,MYSQLI_ASSOC))
{
$tabla.='
<tbody>
<tr style="cursor:pointer">
<td>'.$fila['id_cliente'].'</td>
<td>'.$fila['nombre_cliente'].'</td>
<td>'.$fila['apellido_cliente'].'</td>
<td>'.$fila['n_empresa'].'</td>
<td>'.$fila['colonia'].'</td>
<td>'.$fila['n_direccion'].'</td>
<td>'.$fila['razon_social'].'</td
</tr>
</tbody
';
}
$(document).ready(function() {
var table = document.querySelector('#tabla tr td');
if(table == null){
alert(table);
}else if(table = 1){
for(var i = 1; i < table.rows.length; i++){
table.rows[i].onclick = function(){
document.querySelector("#nombre").value = this.cells[0].innerHTML;
}
}
}
// Instrucciones a ejecutar al terminar la carga
});