run a script automatically

Asked

Viewed 79 times

0

how can I run this script below, at the time the input label is filled?

<script>
$(document).ready(function(){
    var serie = $('#serie_maquina').val();
    var grupo = $('#grupo_maquina').val();
    console.log(serie);
    console.log(grupo);
    $.ajax({
        type:'post',
        url: 'info_maquina_consulta.php',
        data: {
            'serie':serie,
            'grupo':grupo
        },
        erro: function(){
            alert('erro');
        },
        success: function(data){
            $("#maquina_carrega").html(data);
        }

    });
});

EDIT1 follows html as request:

<form>
    <div class="col-sm-6">
        <div class="input-group input-group-md">
            <span class="input-group-addon" id="sizing-addon1">Numero Serie</span>
            <input type="text" class="form-control" name="serie_maquina" id="serie_maquina">
        </div>
    </div>
    <div class="col-sm-6">
        <div class="input-group input-group-md">
            <span class="input-group-addon" id="sizing-addon1">Modelo</span>
            <input type="text" class="form-control" name="grupo_maquina" id="grupo_maquina">
        </div>
    </div>
    <button id="btn_consulta" type="button" class="btn btn-md btn-success">Pesquisar</button>
</form>
  • 2

    What would be input label?

  • Adding HTML will make the problem easier to understand

  • edited the post with html!

  • Assuming I have a button that receives a value="from a query. "how do I pass this value to a php variable in a modal?

  • In case, you no longer want to be executed when opening the page?

  • I ask you to rework the question because your original post poses a question and then here in the comments you question something else. With that, it is not clear the question to which you really seek answer.

Show 1 more comment

1 answer

0

You can use the event focusout to execute as soon as the input is populated and lose focus

$('#inputId').on('focusout', function() {
    //código a ser executado
});

or use the keyup that always runs when a key is pressed and returns to its original position, causing the script to run at the same time that something is typed into the input

$('#inputId').on('keyup', function() {
    //código a ser executado
});

Browser other questions tagged

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