How to show an alert when user navigates to another page without filling the form? I have a form created by a custom module. Now I want to show an alert like ("Please fil the complete form before navigating otherwise lost all the data") if the user navigate to another page without filling all required fields.

How can I do so?
Below are a few modules to consider (quotes included are from the project pages of these modules), sorted by "my recommended one first". It'll depend on your specific requirements which one would fit best for you.


Node Edit Protection (either for D6 or D7).


  A very simple JavaScript based protection that will alert a user if they are navigating away from a modified Node Edit form without saving. It uses a standard JavaScript confirm dialog that allows the user to either continue what they were doing, or cancel the move allowing them the opportunity to save. It marks the form as dirty by using the blur event of the node fields.

SaveGuard (either for D6 or D7).


  ... adds javascript which detects if a form had been modified, and if it has, uses the onBeforeUnload event to pop up a warning to the user if they attempt to navigate away from the page without saving their changes. This works for Firefox, IE, and Safari, but not Opera.

Dirty Forms (only an official release for D6, though for D7 there seems to be a trustworthy patch available also).


  ... provides a javascript behavior that checks forms before users leave the page, warning them if they are about to loose changes and providing an option to remain on the page.
  
  ... The module provides a configuration form that allows setting up a list of forms that should be excluded from the dirtyForms behavior.