keypress event is not getting fired when i press enter key

keypress event is not getting fired when i press enter key

by Thulasi Ram.S

HTML

<form id="test" action="javascript:alert('success!');">
    <input type="text" id="txt1" />
    </form>

JavaScript

$(document).ready(function () {
            var filterID = 1, reg = '^([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$', max = 1000;
           
            $("#txt" + filterID).keypress(txtInput_keypress);

            function txtInput_keypress(e) {
                var code = (e.keyCode ? e.keyCode : e.which);
                var strValue = $(this).val() + String.fromCharCode(e.which);
                var bool = $.trim(strValue).match(reg);
                if (code == 13) {
                    //textbox value submission code
                    //$('form#test').submit(); // if alert is not coming uncoment this line.
                }
                else if (parseFloat($.trim(strValue)) > max) {
                    e.preventDefault();
                }
                else if (bool) {
                    return true;
                }
                else {
                    e.preventDefault();
                }
            }
        });