Search code examples
javascripthtmlformsstack-overflowreset

Form reset Stack overflow at line IE 10, 8


i am using a form like below and getting error in IE Stack overflow at line: 367

<form id="appointmentForm" onreset="resetAppointmentForm()" action="" method="post" novalidate class="appointmentForm">

In above form tag onreset="resetAppointmentForm() attribute is causing error. removing this from markup would solve the error but did not reset form.

function resetAppointmentForm() {
    document.forms['appointmentForm'].reset();
    $('.appointmentForm .alert').remove();
}

Solution

  • In your form tag you have this:

    onreset="resetAppointmentForm()"
    

    And in that function you have this:

    document.forms['appointmentForm'].reset();
    

    So... Triggering a form reset triggers a form reset. That's an infinite recursion. Thus, a stack overflow error.

    Remove that line from within the function. There's no need for an event handler to trigger itself.