how to tell what form to use in javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UGF1bA==?=

    #1

    how to tell what form to use in javascript

    I have a javascript that I am setting a value of a textbox in and have the
    following
    document.forms[0].textbox1.value = total;
    I get a run time error null value but I think the problem is the form index
    0. The web application has about 20 forms, is there anyway to tell what the
    index should be?
    thanks.
    --
    Paul G
    Software engineer.
  • Mark Rae [MVP]

    #2
    Re: how to tell what form to use in javascript

    "Paul" <Paul@discussio ns.microsoft.co mwrote in message
    news:4EDCFE5E-7461-404B-9284-3EF78207F83B@mi crosoft.com...
    >I have a javascript that I am setting a value of a textbox in and have the
    following
    document.forms[0].textbox1.value = total;
    I get a run time error null value but I think the problem is the form
    index
    0. The web application has about 20 forms, is there anyway to tell what
    the
    index should be?
    Can't you refer to the form by its name...?



    --
    Mark Rae
    ASP.NET MVP


    Comment

    • Nathan Sokalski

      #3
      Re: how to tell what form to use in javascript

      Is this an page created by ASP.NET (*.aspx)? If it is, it should only have
      one form. Also, if the textbox was created by an ASP.NET TextBox server
      control (I'm assuming it was since this is an ASP.NET newsgroup), then not
      only will the id attribute in the generated HTML be different than the one
      in your *.aspx source file, but I would recommend using
      document.getEle mentById(...).v alue instead (this is what is normally used,
      and it does not require an index). My suggestions are based on the
      assumption this is an ASP.NET *.aspx Page, if this assumption is incorrect
      we may need to see your source code to determine your problem. Good Luck!
      --
      Nathan Sokalski
      njsokalski@hotm ail.com
      有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


      "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
      news:OZvK$OKNJH A.6124@TK2MSFTN GP04.phx.gbl...
      "Paul" <Paul@discussio ns.microsoft.co mwrote in message
      news:4EDCFE5E-7461-404B-9284-3EF78207F83B@mi crosoft.com...
      >
      >>I have a javascript that I am setting a value of a textbox in and have the
      >following
      >document.for ms[0].textbox1.value = total;
      >I get a run time error null value but I think the problem is the form
      >index
      >0. The web application has about 20 forms, is there anyway to tell what
      >the
      >index should be?
      >
      Can't you refer to the form by its name...?

      >
      >
      --
      Mark Rae
      ASP.NET MVP
      http://www.markrae.net

      Comment

      • Mark Rae [MVP]

        #4
        Re: how to tell what form to use in javascript

        "Nathan Sokalski" <njsokalski@hot mail.comwrote in message
        news:Ohec%23fLN JHA.2760@TK2MSF TNGP06.phx.gbl. ..
        >>I have a javascript that I am setting a value of a textbox in and have
        >>the
        >>following document.forms[0].textbox1.value = total;
        >>I get a run time error null value but I think the problem is the form
        >>index 0. The web application has about 20 forms, is there anyway to
        >>tell what the index should be?
        >>
        >Can't you refer to the form by its name...?
        >http://www.devguru.com/Technologies/...doc_forms.html
        >
        Is this an page created by ASP.NET (*.aspx)? If it is, it should only have
        one form.
        ASP.NET pages can contain as many forms as you like, so long as:

        1) only one of them has the runat="server" tag

        2) they aren't nested


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • =?Utf-8?B?UGF1bA==?=

          #5
          Re: how to tell what form to use in javascript

          thanks for the responses, below is the code, it is aspx pages. I created a
          small sample web app with only 3 webpages and it works fine but when
          integrating it into a large web app I ran into the following problems. When
          I call the javascript function (calcBalancenew ) and try to pass in the
          textbox values there is a java error txbx1 not defined. Note the first
          attribute works since I am just passing in integers but the others fail. The
          second problem is that in the java script function (calcBalancenew ) where I
          try to write the results to textbox 4 with

          document.forms[0].txbx4.value = total;
          I get the error document.forms. 0.txbx4 is null or not an object,
          so it looks like it can not find it, so thinking I am not accessing the form
          correctly.

          The large web app uses a master page and all other pages are content of the
          master page when it gets loaded in.
          I have a simple java function that just adds values in text boxes 1 through
          4 and displays the results in text box 4.
          In the code behind to use the onblur event with asp.net textbox controls for
          4 textboxes I have

          txbx1.Attribute s["onblur"] = "calcBalancenew (7,1,2,3)";
          txbx2.Attribute s["onblur"] =
          "calcBalancenew (txbx1.value,tx tbx2.value,txbx 3.value,txbx4.v alue)";
          txbx3.Attribute s["onblur"] =
          "calcBalancenew (txbx1.value,tx bx2.value,txbx3 .value,txbx4.va lue)";
          txbx4.Attribute s["onblur"] =
          "calcBalancenew (txbx1.value,tx bx2.value,txbx3 .value,txbx4.va lue)";


          --
          Paul G
          Software engineer.


          "Nathan Sokalski" wrote:
          Is this an page created by ASP.NET (*.aspx)? If it is, it should only have
          one form. Also, if the textbox was created by an ASP.NET TextBox server
          control (I'm assuming it was since this is an ASP.NET newsgroup), then not
          only will the id attribute in the generated HTML be different than the one
          in your *.aspx source file, but I would recommend using
          document.getEle mentById(...).v alue instead (this is what is normally used,
          and it does not require an index). My suggestions are based on the
          assumption this is an ASP.NET *.aspx Page, if this assumption is incorrect
          we may need to see your source code to determine your problem. Good Luck!
          --
          Nathan Sokalski
          njsokalski@hotm ail.com
          有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

          >
          "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
          news:OZvK$OKNJH A.6124@TK2MSFTN GP04.phx.gbl...
          "Paul" <Paul@discussio ns.microsoft.co mwrote in message
          news:4EDCFE5E-7461-404B-9284-3EF78207F83B@mi crosoft.com...
          >I have a javascript that I am setting a value of a textbox in and have the
          following
          document.forms[0].textbox1.value = total;
          I get a run time error null value but I think the problem is the form
          index
          0. The web application has about 20 forms, is there anyway to tell what
          the
          index should be?
          Can't you refer to the form by its name...?



          --
          Mark Rae
          ASP.NET MVP
          http://www.markrae.net
          >
          >
          >

          Comment

          • =?Utf-8?B?UGF1bA==?=

            #6
            Re: how to tell what form to use in javascript

            I was able to set the textbox value by using the getElementById as suggested,
            still have the other issue though where it does not recognize the arguments
            being passed into the onblur event. This is in the C# code behind to create
            the onblur events for the web controls.

            txbx2.Attribute s["onblur"] =
            "calcBalancenew (txbx1.value,tx tbx2.value,txbx 3.value,txbx4.v alue)";

            Comment

            • Mark Rae [MVP]

              #7
              Re: how to tell what form to use in javascript

              "Paul" <Paul@discussio ns.microsoft.co mwrote in message
              news:A510E525-C2ED-4512-8330-611A3FABE0F5@mi crosoft.com...
              I was able to set the textbox value by using the getElementById as
              suggested,
              still have the other issue though where it does not recognize the
              arguments
              being passed into the onblur event. This is in the C# code behind to
              create
              the onblur events for the web controls.
              >
              txbx2.Attribute s["onblur"] =
              "calcBalancenew (txbx1.value,tx tbx2.value,txbx 3.value,txbx4.v alue)";
              .
              document.getEle mentById ('<%=txbx4.Clie ntID%>').value= total;
              How about something like:

              "calcBalancenew (" +
              txbx1.ClientID + ".value," +
              txbx2.ClientID + ".value," +
              txbx3.ClientID + ".value," +
              txbx4.ClientID + ".value)";

              The syntax may not be 100% accurate, but you get the idea...


              --
              Mark Rae
              ASP.NET MVP


              Comment

              • =?Utf-8?B?UGF1bA==?=

                #8
                Re: how to tell what form to use in javascript

                ok thanks it worked! It was using the actual text for the client id instead
                of retrieving the client id when the page was rendered.
                --
                Paul G
                Software engineer.


                "Mark Rae [MVP]" wrote:
                "Paul" <Paul@discussio ns.microsoft.co mwrote in message
                news:A510E525-C2ED-4512-8330-611A3FABE0F5@mi crosoft.com...
                >
                I was able to set the textbox value by using the getElementById as
                suggested,
                still have the other issue though where it does not recognize the
                arguments
                being passed into the onblur event. This is in the C# code behind to
                create
                the onblur events for the web controls.

                txbx2.Attribute s["onblur"] =
                "calcBalancenew (txbx1.value,tx tbx2.value,txbx 3.value,txbx4.v alue)";
                .
                document.getEle mentById ('<%=txbx4.Clie ntID%>').value= total;
                >
                How about something like:
                >
                "calcBalancenew (" +
                txbx1.ClientID + ".value," +
                txbx2.ClientID + ".value," +
                txbx3.ClientID + ".value," +
                txbx4.ClientID + ".value)";
                >
                The syntax may not be 100% accurate, but you get the idea...
                >
                >
                --
                Mark Rae
                ASP.NET MVP

                >
                >

                Comment

                Working...