So if you aren't using PHP/ASP/JSP/etc., then the best you can do is "pass along" the page you are coming from.
Several ways to do that. Say the page with the <form> is "myform.html". Okay, so just call it from the various pages via "myform.html?from=contact" or "myform.html?from=orderform" or whatever.
And then you can look for that "from=" in the JS code and do the appropriate thing.
Another way would be to set a COOKIE in each page you come from and then look for the cookie in "myform.html".
Before I go further, though, *can* you use PHP/ASP/JSP for this page?
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.