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.
source
share