Our website is built in ASP.NET and uses a content management system. The CMS came with a wealth of JavaScript files and I decided to use one of these files for form validation. Although the file is over 2,300 lines, from what I can tell it is supposed to return true if the form is valid and false otherwise.

The problem is that a function inside that file seems to get to a certain point, and somehow quit and return true no matter if the form is valid or not.

I am calling this JS from an ASP.NET button control. When the button is clicked, a JS function ValidateForm(document.forms[0]) is called. My ValidateForm function calls another function inside the JS file (which calls another, and another...). No matter what, when that second function is called and executed, code execution stops at some point and the form submits (postbacks). I can see that the validation is working just before the postback, but it is not preventing the form from being submitted, and it also stops executing any code after it.

Here is my code:

 <asp:Button ID="SubmitBtn" runat="server" Text="Submit Form" CausesValidation="false" CssClass="submit_button" OnClientClick="FmValidate(document.forms[0]); return false;" OnClick="SubmitBtn_Click" />
My Javascript:
        function FmValidate(formObj) {
             var strError = ''; var e = null;
              if (strError == '' && 'function' == typeof design_validateHtmlForm) {

                 // this line causes execution to stop - located in external JS file
                 // code states "Returns first invalid element, or null."
                  e = design_validateHtmlForm(formObj);

                  alert("e is " + e);
                  if (e) { strError = e.title; }
                  return false;
In my ASP.NET button, changing the OnClientClick method to "return false" will prevent form submission, but "return FmValidate(formObj);" will not if that function calls design_validateHtmlForm(formObj).

I receive the message box saying "before" but I never receive the second one.

I have debugged using Fire bug, but the code seems to cycle through each element on the page and stepping through the code is not realistic (I have done so for 20-minute stretches).

I am wondering if anyone has any ideas what code I could look for that would stop execution and return true no matter what, or how I could begin debugging this monster.