Ok, so I am completely baffled by this one... working in PHP with some Javascript.
I have created two nearly identical forms with only a submit button. The first one on the page never triggers the onsubmit function call, but the second one always does. Here is the code:
echo('<form action="restricted.php?page=dashboard&sm=unitreport" name="form1" method="post" onsubmit="alert(`test1`);">');
echo('<input type="submit" name="testsubmit1" value="submit1">');
echo('</form>');
echo('<form action="restricted.php?page=dashboard&sm=unitreport" name="form2" method="post" onsubmit="alert(`test2`);">');
echo('<input type="submit" name="testsubmit2" value="submit2">');
echo('</form>');
The ONLY difference between these two are that I numbered them "1" and "2".
With the code above, I never receive the alert "test1" but always receive alert "test2".
If I reverse the order of these two forms, then I never receive the alert "test2" but always receive the alert "test1".
In other words, it's only ever triggering the onsubmit call for the second form and never the first, but I have absolutely no idea why.
I've been trying to figure this one out for an hour now through trial and error and no matter what I try, I haven't been able to get both forms to trigger their respective onsubmit functions. w3schools.com and google searches haven't provided any clues yet either.
Any ideas?
Ok... So I found the solution to my problem, and it wasn't at all what I expected. I decided to post it as an answer to help in case someone else runs into a similar problem.
I went ahead and copied the code into a new blank page and sure enough, it worked fine. Both forms were triggering their respective messages.
It turns out that about 500 lines of code earlier, there was another html form, and somehow, the closing form tag got deleted and went unnoticed.
Thus the "first" of my two forms was being interpreted as a continuation of the earlier form in my code, which doesn't have an onsubmit call!
Doh! Embarrassing lesson learned.