Submission of HTML form with javascript validation delay in Google Chrome

I realized that there is some delay in submitting a javascript confirmation form in Google Chrome during my development.

So, I tried the test with a small html page to make sure that the delay was caused by my application. But this is still happening on the test page.

I just donโ€™t want to acknowledge the onsubmit form event, as there will be several views for different purposes.

So here is my test html.

<html> <head><title>Test</title></head> <body> <script type="text/javascript"> var currentTime = new Date() document.write(currentTime.getMilliseconds()); </script> <form name="input" method="post"> <input type="submit" value="Submit" onclick="javascript:return confirm('Are you sure to submit?');" /> </form> </body> </html> 

How can I avoid this delay? Do I need to change anything from my end?

Please correct if this is caused by my html that is not creating a good shape or something is missing.

Thanks.

+4
source share
2 answers

There are two problems in the code. Less significant is that you use javascript: in your onclick attibute, which is not needed. on* attributes are implicitly evaluated as JavaScript already - they do not look like hyperlinks.

Secondly, and most importantly, the value of the timer that you display on the screen does not show what you think. It just gets the current date and time and retrieves the millisecond component. This gives you a random number from 0 to 999. If this is what you use to determine the send delay, you are mistaken. Be sure that the form will be submitted as soon as you click OK in the confirmation dialog box, and any delay that you experience is fully related to the page load time (provided that there are no page upload scripts).

0
source

Oddly enough, I had the same problem as you, but it also appeared in FF ... After the remade things, I came up with:

 <form name='doClear' action='index.php' method='post' > <input type='submit' value='Clear All' onclick='return confirm(\"Are you sure you want to clear all? This cannot be undone!\");' /> </form>"; 

Which works instantly for me. I'm not sure where my problems came from before, but now everything is working fine. Good luck.

0
source

All Articles