Why does one enter keypress runs (inside) through this code twice?
I've tried keypress, keydown and also event.preventdefault() to no avail.

    $(document).keydown(function (e) {
        if (e.which == 13) {
           alert("0")
            var focado = document.getElementById(document.activeElement.id), fim = focado.id.substring(1),
                inicio = focado.id.substring(0, 1),
                fimseg = fim,
                anterior = inicio + (fim - 1);

            alert("1")


            alert("focado " + focado.id + " fim " + fim + " inicio " + inicio + " fimseg " + fimseg + " anterior " + anterior);
        }
});

and only after giving this 3 messages twice it would continue to the remaining code I trimmed and isn't shown.
thanks

Hmm... You use it on the whole document? I have a feeling that the event is bubbled from an element inside the page and the whole document. Have you tried to change from $(document) to a specific element and/or $(window) to see if it still acts the same way?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.