Javascript or Jquery, onblur event

Asked

Viewed 224 times

0

Good morning, I want to update the database with the information I type in the input, as soon as this input loses Focus with onblur I want it to send the data to the php page that will update the database. example below.

 <input type="text" size="2" id="n1" onblur="" value="<?=$aln->n1?>"></td>

From now on I thank you.

  • there is a need not to send the data in a form? ja tested via ajax?

  • I forgot to mention, I am not using form, I am using a table in which I put the student note that is Nota1.

1 answer

0

Hello, good afternoon, there are some ways to do this, but we will use the functions blur and ajax from the jQuery library, as it is one of the simplest and easiest ways to do this.

The Blur function is triggered when that particular input loses focus, just as we want. The Ajax function serves to execute asynchronous requests to the server in a simple way. See:

$(documentos).ready(function (){
    $("#n1").blur(function (){
        var valor = $(this).val(); // pega o valor do campo

        $.ajax({
            method: "POST",
            url: "servidor.php", // Seu servidor 
           data: {valorInput: valor} // Envia o post valorInput para o servidor
        });
    });
});



I hope I helped, hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.