0

I have made this script below is working fine in chrome by the help of someone in stackoverflow.

(function($) {
$.fn.enterAsTab = function(options) {
    var settings = $.extend({
        'allowSubmit': false
    }, options);
    $(this).find('input, select, textarea, button').on("keypress", {localSettings: settings}, function(event) {
        if (settings.allowSubmit) {
            var type = $(this).attr("type");
            if (type == "submit") {
                return true;
            }
        }
        if (event.keyCode == 13) {
            var inputs = $(this).parents("form").eq(0).find(":input:visible:not(:disabled):not([readonly])");
            var idx = inputs.index(this);
            if (idx == inputs.length - 1) {
                idx = -1;
            } else {
                inputs[idx + 1].focus(); // handles submit buttons
            }
            try {
                inputs[idx + 1].select();
            }
            catch (err) {
                // handle objects not offering select
            }
            return false;
        }
    });
    return this;
};

})(jQuery);

But this code is not fully working in Firefox. The not working part is the select. I cannot use enter to move to next field when I am in a dropdown (Select).

Thank you in advance.

Daniel Adinugroho
  • 1,399
  • 2
  • 11
  • 21

1 Answers1

0

event.keycode is not supported by Firefox. You need to use event.which for Firefox.

Take a look: window.event.keyCode how to do it on Firefox?

Community
  • 1
  • 1
Sam P
  • 1,821
  • 13
  • 26
  • Thanks for the prompt response. The problem is only in dropdown (select), on buttons, textarea and textfields are working fine. Hence, I think the keyCode should be okay. I have changed to which as well but still the same. Someone has made the code here http://codepen.io/anon/pen/dmvEy – Daniel Adinugroho May 27 '14 at 12:55