Check the type with jquery

2

Well I have two buttons on a form, they are:

<button type='reset' onclick="history.back()">CANCELAR</button>
<button type='submit'>ok</button>

I have the following jquery that identifies the click on the button and sends the form:

$(document).ready(function () {
    $("button").click(function () {

            // Envia formulário
            $("form").submit();

    });
});

I need the $("form").submit(); password executed only when the clicked button is type='submit' .

Is it possible to do this with jquery?

    
asked by anonymous 28.03.2017 / 21:18

2 answers

3

Use a attribute selector :

$("button[type=submit]").click(function () {
   $("form").submit();
});
    
28.03.2017 / 21:24
0

I believe that changing the button type from reset to button is enough, the code would look like this:

<type='button' onclick="history.back()">CANCELAR</button>
    
28.03.2017 / 21:22