Form submit in IE11 doesn't work correctly

2.8k Views Asked by At

I have a problem with the form onsubmit function in IE 11. When the submit button was triggered, the "doSomething()"-function will be called. Inside the "doSomething()" function I call another function that does some input-validation stuff. This function always returns false but sets a flag to true if all validation errors are gone. If the flag was set to true, the "doSomething()"-function returns true and the form will be submitted and the action is called. This pattern works in Firefox, Chrome and Safari but doesn't in IE11. In IE it calls the action before the "doSomeValidation()"-Function is ready. :-/ Can anybody help me out here? Thanks a lot!!!

<form action="headToNextPage.php" onsubmit="return doSomething()">

js

flag = false, // a global flag inside the js-script

function doSomeValidation(){
// validate the inputs and set "flag" to true if all errors are gone
}

function doSomething(){
   doSomeValidation(); // do the validation stuff

   if(flag==true) {
   // do some other stuff
     return true
   }

   return false;
}
2

There are 2 best solutions below

7
On

Replace comma after false to semi colon and add some alert inside the dosomething method its works in IE11 surely flag = false;

0
On

I solved it. Problem was, that I called the JS .startsWith(..)-function on a string inside of the jQuery $( document ).ready(..)-function. Chrome, Firefox and Safari ignored it, but IE went crazy with it but didn't show any errors. I took the .indexOf(..)-function instead and it worked. thanks to all for helping me out here!