3

I have a third party form to track users on the page. I need to track all page submits on the page including submit fails due to js validations. Broad structure is as following:

<form>
//Elements
</form>
<a id="btnSubmit"></a>

I do not have control over structure of the form. To track the form submits I am using anchor tag click event: $('#btnSubmit').click(function () { //my code }); I am not using form.submit as the js code used in form validation prevents form.submit event from being called. It works well with click event except when user submits form with enter key. How can I track enter key form submit without form.submit?

Ruchit Rami
  • 2,273
  • 4
  • 28
  • 53

2 Answers2

4

You could try listening for the enter key being pressed on one of the input fields, or whatever suits in your form

$('input').keypress(function(e) {
        if(e.which == 13) {
            //your submit code
        }
    });
andy mccullough
  • 9,070
  • 6
  • 32
  • 55
-1

instead of click you can do is use the event "submit" for it.

Please look at the link https://api.jquery.com/submit/ for more details.

Sumit Surana
  • 1,554
  • 2
  • 14
  • 28
  • jquery submit binds to javascript submit, which the event has been blocked? – andy mccullough Jul 23 '15 at 10:34
  • As mentioned in the question: I am not using form.submit as the js code used in form validation prevents form.submit event from being called. – Ruchit Rami Jul 23 '15 at 10:37
  • @RuchitRami sorry my mistake, you can try is the following stackoverflow discussion http://stackoverflow.com/a/5931345/3855179. – Sumit Surana Jul 23 '15 at 10:40
  • you can write one method and call it when one of the two method is generated, but of course you would require to handle two different events, I am at least not able to think of other options if form.submit is not usable. – Sumit Surana Jul 23 '15 at 10:42