I was able to solve it using jQuery’s Focus(). I define that the field will have the focus and create an event for when it is in focus, in this event I send the data using Ajax. The $n variable serves to differentiate the id’s, so when it goes to look for the id’s I put an echo in PHP $n, thus having, each item that is found in the bank an index set by $n and each numbered id. In the end, the focus shifts to the other input because this has no event associated, I did it because, in the tests he was repeating endlessly the sending of the last and with this "way" solved. I don’t need user interaction.
<?php
$connect = mysqli_connect("localhost", "login", "senha", "banco") or die (mysql_error ());
$sql = "SELECT `ddd_deps`, `tel_deps`, `nome_deps` FROM `deps` WHERE `sit_deps` = 1 AND `usu_login_usu` = '".$_GET['usu']."'; ";
$result = mysqli_query($connect, $sql);
$n=1;
//lista os dados em inputs para puxá-los pelo id
while ($row = mysqli_fetch_assoc($result)){
echo "<input type='text' name='ddd".$n."' id='ddd".$n."' required='required' value='".$row["ddd_deps"]."'>";
echo "<input type='text' name='tel".$n."' id='tel".$n."' required='required' value='".$row["tel_deps"]."'>";
echo "<input type='text' name='nome".$n."' id='nome".$n."' required='required' value='".$row["nome_deps"]."'><br>";
?>
<!--script para enviar para servidor via get-->
<script>
$(function(){
$("#nome<?php echo $n; ?>").focus();
});
$( "#nome<?php echo $n; ?>" ).focus(function() {
$.ajax({
type : 'get',
url : 'http://'+ $('#ip').val()+':8443/server',
data : 'ddd='+ $('#ddd<?php echo $n; ?>').val() +'&tel='+ $('#tel<?php echo $n; ?>').val() +'&nome='+ $('#nome<?php echo $n; ?>').val(),
dataType : 'html',
success : function(txt){
$("#ddd<?php echo $n; ?>").focus();
}
});
});
</script>
<?php
$n++;
}
?>
You can show the code you have and explain what data you want to send without interaction?
– Sergio
Couldn’t do everything in the page load?
– Marconi