Recieving Error: 'theForm' is undefined

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Sokalski

    Recieving Error: 'theForm' is undefined

    I have an ASP.NET application which is giving the following JavaScript
    error:

    'theForm' is undefined

    However, when I did a View Source I noticed that ASP.NET added the following
    code:

    <script type="text/javascript">
    <!--
    var theForm = document.forms['form1'];
    if (!theForm) {
    theForm = document.form1;
    }
    function __doPostBack(ev entTarget, eventArgument) {
    if (!theForm.onsub mit || (theForm.onsubm it() != false)) {
    theForm.__EVENT TARGET.value = eventTarget;
    theForm.__EVENT ARGUMENT.value = eventArgument;
    theForm.submit( );
    }
    }
    // -->
    </script>

    I was told in a previous posting that the reason for the error is that the
    script containing the declaration and assigning of a value to it occur
    before the

    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。



  • Scott M.

    #2
    Re: Recieving Error: 'theForm' is undefined

    If the page does not have a form named "form1", then the variable
    declaration will fail and the variable "theForm" won't be able to be
    created.


    var theForm = document.forms['form1'];


    "Nathan Sokalski" <njsokalski@hot mail.comwrote in message
    news:Ob7CHA8qHH A.3380@TK2MSFTN GP03.phx.gbl...
    >I have an ASP.NET application which is giving the following JavaScript
    >error:
    >
    'theForm' is undefined
    >
    However, when I did a View Source I noticed that ASP.NET added the
    following code:
    >
    <script type="text/javascript">
    <!--
    var theForm = document.forms['form1'];
    if (!theForm) {
    theForm = document.form1;
    }
    function __doPostBack(ev entTarget, eventArgument) {
    if (!theForm.onsub mit || (theForm.onsubm it() != false)) {
    theForm.__EVENT TARGET.value = eventTarget;
    theForm.__EVENT ARGUMENT.value = eventArgument;
    theForm.submit( );
    }
    }
    // -->
    </script>
    >
    I was told in a previous posting that the reason for the error is that the
    script containing the declaration and assigning of a value to it occur
    before the
    >
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

    >

    Comment

    • bruce barker

      #3
      Re: Recieving Error: 'theForm' is undefined

      either the script referencing theForm occurs before the declaration or
      form1 is not defined (a form tag with name form1).


      -- bruce (sqlwork.com)


      Nathan Sokalski wrote:
      I have an ASP.NET application which is giving the following JavaScript
      error:
      >
      'theForm' is undefined
      >
      However, when I did a View Source I noticed that ASP.NET added the following
      code:
      >
      <script type="text/javascript">
      <!--
      var theForm = document.forms['form1'];
      if (!theForm) {
      theForm = document.form1;
      }
      function __doPostBack(ev entTarget, eventArgument) {
      if (!theForm.onsub mit || (theForm.onsubm it() != false)) {
      theForm.__EVENT TARGET.value = eventTarget;
      theForm.__EVENT ARGUMENT.value = eventArgument;
      theForm.submit( );
      }
      }
      // -->
      </script>
      >
      I was told in a previous posting that the reason for the error is that the
      script containing the declaration and assigning of a value to it occur
      before the
      >

      Comment

      • Scott M.

        #4
        Re: Recieving Error: 'theForm' is undefined

        And, remember "Form1" != "form1".



        "Scott M." <s-mar@nospam.nosp amwrote in message
        news:Om2Dsu9qHH A.4108@TK2MSFTN GP06.phx.gbl...
        If the page does not have a form named "form1", then the variable
        declaration will fail and the variable "theForm" won't be able to be
        created.
        >
        >
        var theForm = document.forms['form1'];
        >
        >
        "Nathan Sokalski" <njsokalski@hot mail.comwrote in message
        news:Ob7CHA8qHH A.3380@TK2MSFTN GP03.phx.gbl...
        >>I have an ASP.NET application which is giving the following JavaScript
        >>error:
        >>
        >'theForm' is undefined
        >>
        >However, when I did a View Source I noticed that ASP.NET added the
        >following code:
        >>
        ><script type="text/javascript">
        ><!--
        >var theForm = document.forms['form1'];
        >if (!theForm) {
        > theForm = document.form1;
        >}
        >function __doPostBack(ev entTarget, eventArgument) {
        > if (!theForm.onsub mit || (theForm.onsubm it() != false)) {
        > theForm.__EVENT TARGET.value = eventTarget;
        > theForm.__EVENT ARGUMENT.value = eventArgument;
        > theForm.submit( );
        > }
        >}
        >// -->
        ></script>
        >>
        >I was told in a previous posting that the reason for the error is that
        >the script containing the declaration and assigning of a value to it
        >occur before the
        >>
        >--
        >Nathan Sokalski
        >njsokalski@hotm ail.com
        >http://www.nathansokalski.com/
        >>
        >
        >

        Comment

        • Alexey Smirnov

          #5
          Re: Recieving Error: 'theForm' is undefined

          On Jun 11, 2:24 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
          I have an ASP.NET application which is giving the following JavaScript
          error:
          >
          'theForm' is undefined
          >
          However, when I did a View Source I noticed that ASP.NET added the following
          code:
          >
          <script type="text/javascript">
          <!--
          var theForm = document.forms['form1'];
          if (!theForm) {
          theForm = document.form1; }
          >
          function __doPostBack(ev entTarget, eventArgument) {
          if (!theForm.onsub mit || (theForm.onsubm it() != false)) {
          theForm.__EVENT TARGET.value = eventTarget;
          theForm.__EVENT ARGUMENT.value = eventArgument;
          theForm.submit( );
          }}
          >
          // -->
          </script>
          >
          I was told in a previous posting that the reason for the error is that the
          script containing the declaration and assigning of a value to it occur
          before the
          >
          --
          Nathan Sokalski
          njsokal...@hotm ail.comhttp://www.nathansokal ski.com/
          try

          var theForm = document.getEle mentById("form1 ");

          Comment

          • Juan T. Llibre

            #6
            Re: Recieving Error: 'theForm' is undefined

            He can't try that, Alexei, because the code is being injected by ASP.NET.

            He can't change the embedded javascript funtions, if he's using ASP.NET 2.0.
            There's a chance he mioght be able to do that, if he's using ASP.NET 1.1.

            All he'd have to do is edit the scripts located in
            \wwwroot\aspnet _client\system_ web\1_1_4322.

            The problem doesn't seem to be that the function is buggy, though.

            If Nathan were to rename the page's form to "form2",
            instead of naming it "form1", he should see this :

            <script type="text/javascript">
            <!--
            var theForm = document.forms['form2'];
            if (!theForm) {
            theForm = document.form2;
            }
            function __doPostBack(ev entTarget, eventArgument) {
            if (!theForm.onsub mit || (theForm.onsubm it() != false)) {
            theForm.__EVENT TARGET.value = eventTarget;
            theForm.__EVENT ARGUMENT.value = eventArgument;
            theForm.submit( );
            }
            }
            // -->
            </script>

            Notice that the source reveals that the script has picked up the form's new name.

            If that doesn't show up, and the error persists, it's a timing problem.
            The javascript is running before the form has been rendered.




            Juan T. Llibre, asp.net MVP
            asp.net faq : http://asp.net.do/faq/
            foros de asp.net, en español : http://asp.net.do/foros/
            =============== =============== ========
            "Alexey Smirnov" <alexey.smirnov @gmail.comwrote in message
            news:1181564838 .967123.116540@ m36g2000hse.goo glegroups.com.. .
            On Jun 11, 2:24 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
            >I have an ASP.NET application which is giving the following JavaScript
            >error:
            >>
            >'theForm' is undefined
            >>
            >However, when I did a View Source I noticed that ASP.NET added the following
            >code:
            >>
            ><script type="text/javascript">
            ><!--
            >var theForm = document.forms['form1'];
            >if (!theForm) {
            > theForm = document.form1; }
            >>
            >function __doPostBack(ev entTarget, eventArgument) {
            > if (!theForm.onsub mit || (theForm.onsubm it() != false)) {
            > theForm.__EVENT TARGET.value = eventTarget;
            > theForm.__EVENT ARGUMENT.value = eventArgument;
            > theForm.submit( );
            > }}
            >>
            >// -->
            ></script>
            >>
            >I was told in a previous posting that the reason for the error is that the
            >script containing the declaration and assigning of a value to it occur
            >before the
            >>
            >--
            >Nathan Sokalski
            >njsokal...@hot mail.comhttp://www.nathansokal ski.com/
            >
            try
            >
            var theForm = document.getEle mentById("form1 ");
            >

            Comment

            • Alexey Smirnov

              #7
              Re: Recieving Error: 'theForm' is undefined

              On Jun 11, 3:01 pm, "Juan T. Llibre" <nomailrepl...@ nowhere.com>
              wrote:
              He can't try that, Alexei, because the code is being injected by ASP.NET.
              >
              On Jun 11, 2:24 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
              However, when I did a View Source I noticed that ASP.NET added the following
              code:
              Okay, I see. Sorry!

              Comment

              Working...