1

i am using asp.net and following code to submit form on enter key press it is working but only refreshing same page and not calling button click event in server side code and without saving data it is comming back to same form, even without the jquery code again same thing happening don't know why but in some forms enter key press working fine and saving data without even following jquery code.

$(function() {
    $("form input").keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
        alert('Alert is Working but data is not being Save Only Refresh');
            $('button[type=submit].default').click();
            return false;
        } else {
            return true;
        }
    });
});

1 Answer 1

1

This may be because the web protocol (HTTP) is stateless...it does not save the state of the objects on page when page is refreshed...pressing enter in your case only refreshes the page and hence the data is not getting saved. Try calling the button click event out-side the key-press function. It should then save your data.

Try this.. $('form').submit(function () {return false;}); make sure you put ur button tag inside form tag.

Sign up to request clarification or add additional context in comments.

1 Comment

but in some forms it is submitting form

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.