IE7 and IE8 do not call onsubmit javascript * before * submittion

I have a search form:

<form class="searchForm" id="topSearchForm" action="/search.ds">

which has an onsubmit event attached to it, running javascript. The purpose of this javascript is to clear certain form fields before submitting the form based on certain criteria.

To be clear what should happen:

User input β†’ User clicks the search button (or presses β€œenter”) β†’ Skips Javascript β†’ fields β†’ the form is submitted

This works exactly as expected in all browsers except IE7 and IE8. Javascript works, but for some reason, the form submission is executed before the fields are cleared by javascript. This forces the submitted page to include data from the fields that should have been cleared.

I only control (certain parts) of the user interface and cannot process anything after submitting the form. For ease of use, it is important that these fields (which should be cleared) are filled in until the user submits the form.

Why is the internal logic different in IE7 and IE8 (it works fine in IE9 and "in all other browsers)? Is there a way around this problem?

Here is another code to explain:

I am attaching an event to the form:

var formElement = document.getElementById("topSearchForm");
[...]
formElement.attachEvent('onsubmit', function() {clearForSubmit()});

and clearForSubmit is defined and launched.

+3
source share
2 answers

You can try something like this in js

<form onsubmit="clearForSubmit(); return false;">

it will NOT send the form, you can send the form after you clear it with

form_name.submit();
+1
source

onclick onsubmit, .

0

All Articles