Put jQuery function on button

Asked

Viewed 119 times

0

I need to place a function call on submit, check if there is at least one file in the database and if there is no form it is not submitted.

2 answers

2

You will need a call AJAX to the server to check whether or not the database entry exists. The return of this call may be a JSON indicating whether the entry exists or not.

Generic code of what you can do. I believe you can adapt.

$('input[type="submit"]').on('click',function(e){
    e.prenventDefault(); // previne form de ser submitado
    $.get(
        'controlador.php', // código em php que recebe chamada ajax 
        {
            data : dados // eventuais dados
        },
        function(resposta){
            if (resposta.temEntrada){
                $('#formId').submit(); // submita form de id `formId`
            }else{
               // faz outra coisa
            }
        }
    );
});

0

You must go via AJAX to check if the record exists in the database. On return you submit or not the form.

Or you can submit, check, and if there is no record you will pop an exception.

There are several ways to solve your problem, I would particularly opt for ajax. Send everything via ajax.

  • a practical example of at least one of the ways of doing it is important for understanding, even why he should know that he has to do it, but not know in terms of code

  • I am doing this: <input type="Submit" value="Finish Registration"id="czech"> $(Document). ready( Function(){ $("#czech"). on('click',checaUpload(){ var id_credor = $("#id_credor"). val(); Alert(id_credor); }) !

  • Gustavo, your code doesn’t seem to run when clicked. Ideal is: $("#checa").on('click', function() { alert($("#id_credor").val()); });

  • I did this and it is not blocking the send form $(Document). ready( Function(){ $("#send"). on('click', Function(){ var id_credor = $("#id_new_credor"). val(); $. ajax({ url: ".. /php/checaUpload.php", type: "POST", dataType: "json", date: "id_credor="+id_credor, error: Function(date){ var status; status = (date.status); if(status == 0){ Return false } }, }); }); });

  • Maybe you don’t slash because your boot is like Ubmit. .

Browser other questions tagged

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