How to call onblur from that Ubmit?

Asked

Viewed 134 times

0

$("#more").submit(function (event) {
    event.preventDefault();

    alert('estou aqui');
    var link = $("#link").val();
    var date = $("#date-foundation").val();

    var validation = true;

    if (link === null || link === '') {
        $("#link").addClass("input-required");
        validation = false;
    }

    if (validation === true) {
        $.ajax({
            url: './model/functions/link_repeat.php',
            type: 'POST',
            data: {link: link},
            success: function (data) {
                alert(data);
                if (data === 'true') {
                    $("#link").addClass("input-required");
                    $("#alert-link").append("<span style='color:red'><b>Esse link já existe! Escolha outro!</b></span>");
                    return;
                }
            }
        });
    }
});
  • Hello Ana, can you explain better what you mean by "call the onblur from that Ubmit"? Do you have any event headphones blur that you want to trigger when `Submit`` occurs, that’s it?

  • Actually the onblur I call through the function name right. And in this case I want to put it in my input. How to put? onblur = ?

  • So you can’t just invoke the function before ajax? simply with minhaFuncao(); in the code?

  • then in this case my function has no name, as you would call her?

  • Hmmm... I still don’t get it. Can you explain in steps what you want to happen? For example: click on Submit > triggers the form’s Submit and runs the code in question > and then?...

  • So I have an input where I’m doing a validation, I just want it to validate if the person changes what’s written. If the person does not touch the input is not to validate.

  • Okay, what’s the logic to validate? What do you call that logic? It’s through blur when you click the button submit?

Show 2 more comments

1 answer

0

Perhaps the concept of onBlur is not clear.
Check the link to better understand the event generated by taking the mouse over an object and the event after you change the value of an element (onBlur x onChange in English)

See if what you need is this in your javascript file

var inputsAlterados = 0;

$('.classeParainputs').change(function () {
    inputsAlterados++;
});

$("#botaoGravar").submit(function () {
    if (inputsAlterados > 0) {
        /**
            Continuidade da lógica para salvar
        **/
    }
});

Browser other questions tagged

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