Room of a pleinolijf

Ask yourself this: how do I want to be remembered ?

JavaScript : Preventing Form Submit When Closing Window


I have this page, on which I have a button. The button does nothing more than window.close(). But the problem is that the page contains a form onsubmit script, which checks to see if the sum of all dropdownlists equals 10.
So when I implemented the button to immediately close the window, it would trigger the submit on the form. To solve this, you have to write window.close();return false; instead of just window.close();.

You would think that when window.close() executes, the form won’t do a submit… I didn’t think this was obvious, that’s why I made a post about it. Hope it’s useful to someone.

TechnoratiTechnorati Tags: , , ,


Author: pleinolijf

father | volleyballer | software engineer

2 thoughts on “JavaScript : Preventing Form Submit When Closing Window

  1. What is really happening here? ,


  2. The problem is that when I press the button that closes the window, I do not want any submit to happen. In order for this to work, you have to include “return false;” after your “window.close;”. Otherwise, the submit form would trigger, which is a behaviour I do not want for this certain case.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s