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".

Dev
  • 781
  • 9
  • 29
  • 1
    Does this question help? http://stackoverflow.com/questions/4762594/jquery-keyup-for-tab-key – Paul Aug 06 '12 at 10:46
  • e.keyCode comes as "undefined" failing to identify the event keycode. – Dev Aug 06 '12 at 10:57

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();
                }

            }

    });
Dev
  • 781
  • 9
  • 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.

Dev
  • 781
  • 9
  • 29