1

I have the following script

   $('.formfield:not(.NoHighlight, #P_PH_PHONE, #P120_PH_EMAIL) :input').focus(function(e){


            var currentElementonForm = $(this); 
            if(currentElementonForm.is("input[type=submit]")){
                currentElementonForm.parents('form').submit();
            }

    });

Currently, the page submits when a user tabbed (keyborad TAB button) to the submit button. I would like to stop this but only do it when a user clicked not tabbed to the button. Hopefully, the question is clear and happy to give anymore details. I did try detecting e.keyCode == 9 but it logs it as "undefined".

Chin
  • 753
  • 8
  • 29

2 Answers2

0

enter code hereEdit : Since keyCode is not working we can approach this problem differently ?

$('.formfield input[type=submit]').click( function() {
      $(this).parents('form').submit();
  });

  $('.formfield:not(.NoHighlight, #P_PH_PHONE, #P120_PH_EMAIL) :input').focus(function(e){
            var currentElementonForm = $(this); 
            if(currentElementonForm.is("input[type=submit]")){
                var code = e.keyCode || e.which;
                if (code !== 9) {
                    currentElementonForm.parents('form').submit();
                }

            }

    });
Chin
  • 753
  • 8
  • 29
0

I had to find an alternative way to deal with this issue. The problem was on "focus" event does not return a keyCode even when using the TAB key. So had to work with a different solution. This was something new to me and hopefully this might benefit someone having the same issue.

Chin
  • 753
  • 8
  • 29