Clicking a link in my page submits an ajax request and loads the response in a modal dialog window. That response contains a form with id ‘ModalForm’. What I am trying to achieve is to prevent the default form behavior of the ‘Enter’ key for this specific form and replace it with execution of a JS function that I wrote. Unfortunately I can’t get it to work nor I receive an alert message. Here’s my code:
jQuery(function (){
jQuery('#ModalForm').keypress(function(e){
alert(e.keyCode);
if (e.keyCode == 13) {
modalWindowSubmit();
}
});
jQuery('#ModalForm').on('keypress', (function() {
alert('hi');
});
});
Thanks in advance!
You have to bind the event on the form in the “success” of the ajax call