Problems with ASP.Net object and Javascript

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

    #1

    Problems with ASP.Net object and Javascript

    I have a function:

    function SalaryDisplay(m e)
    {
    var salaryMinLabel = document.getEle mentById("Salar yMin");
    salaryMinLabel. value = 200;
    alert("after setting salaryMinLabel = " + salaryMinLabel. value);
    }

    I also have an asp.net object:

    <asp:label id="SalaryMin" runat="server" />

    Which renders into:

    <span id="SalaryMin"> </span>

    The function seems to find the span fine. The alert box shows that it is
    set to 200. But the web page never shows it.

    Is there a problem setting the span element?

    Thanks,

    Tom


  • tshad

    #2
    Re: Problems with ASP.Net object and Javascript


    "tshad" <tscheiderich@f tsolutions.com> wrote in message
    news:OwZ4e.1040 1$FN4.3053@news svr21.news.prod igy.com...[color=blue]
    >I have a function:
    >
    > function SalaryDisplay(m e)
    > {
    > var salaryMinLabel = document.getEle mentById("Salar yMin");
    > salaryMinLabel. value = 200;
    > alert("after setting salaryMinLabel = " + salaryMinLabel. value);
    > }
    >
    > I also have an asp.net object:
    >
    > <asp:label id="SalaryMin" runat="server" />
    >
    > Which renders into:
    >
    > <span id="SalaryMin"> </span>
    >
    > The function seems to find the span fine. The alert box shows that it is
    > set to 200. But the web page never shows it.
    >
    > Is there a problem setting the span element?[/color]

    I just change the object to an asp:textbox which renders into an input field
    on the screen and this works fine.

    In asp, you use a label object to display (and change) text on the screen
    that is not part of an input type of field.

    Is there a way to do this in Javascript/html?

    I just want to be able to display the results of some calculations on a
    field that the user inputs as just a label.

    Thanks,

    Tom[color=blue]
    >
    > Thanks,
    >
    > Tom
    >[/color]


    Comment

    • David Dorward

      #3
      Re: Problems with ASP.Net object and Javascript

      tshad wrote:
      [color=blue]
      > var salaryMinLabel = document.getEle mentById("Salar yMin");
      > salaryMinLabel. value = 200;[/color]
      [color=blue]
      > <span id="SalaryMin"> </span>[/color]
      [color=blue]
      > Is there a problem setting the span element?[/color]

      Span elements don't have values. You need to create a new text node then
      append it to the element to add text to it. Look at the JavaScript section
      of the DOM 1 specification. http://w3.org/DOM/

      --
      David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
      Home is where the ~/.bashrc is

      Comment

      • tshad

        #4
        Re: Problems with ASP.Net object and Javascript

        I tried to do the same thing with the <lable> label item and had the same
        problem. It shows that the value was changed, but it didn't seem to do
        anything on the screen:

        Yearly Compensation:<i nput name="SalaryMin " type="text" id="SalaryMin"
        />&nbsp;/&nbsp;
        <span id="SalaryMax"> </span>
        <Label id="SalaryMin2 " for="SalaryMin" >This is a test</Label> />

        The javascript code:

        function SalaryDisplay(m e)
        {
        alert("this.val ue = " + me.value);
        var salaryMinLabel = document.getEle mentById("Salar yMin2");
        salaryMinLabel. innerText = 200;
        alert("after setting salaryMinLabel = " + salaryMinLabel. value);
        }

        This doesn't seem to work. I tried to do it directly
        (SalaryMin2.inn erText=200), but that didn't work either.

        Tom

        "tshad" <tscheiderich@f tsolutions.com> wrote in message
        news:VBZ4e.1040 2$FN4.1589@news svr21.news.prod igy.com...[color=blue]
        >
        > "tshad" <tscheiderich@f tsolutions.com> wrote in message
        > news:OwZ4e.1040 1$FN4.3053@news svr21.news.prod igy.com...[color=green]
        >>I have a function:
        >>
        >> function SalaryDisplay(m e)
        >> {
        >> var salaryMinLabel = document.getEle mentById("Salar yMin");
        >> salaryMinLabel. value = 200;
        >> alert("after setting salaryMinLabel = " + salaryMinLabel. value);
        >> }
        >>
        >> I also have an asp.net object:
        >>
        >> <asp:label id="SalaryMin" runat="server" />
        >>
        >> Which renders into:
        >>
        >> <span id="SalaryMin"> </span>
        >>
        >> The function seems to find the span fine. The alert box shows that it is
        >> set to 200. But the web page never shows it.
        >>
        >> Is there a problem setting the span element?[/color]
        >
        > I just change the object to an asp:textbox which renders into an input
        > field on the screen and this works fine.
        >
        > In asp, you use a label object to display (and change) text on the screen
        > that is not part of an input type of field.
        >
        > Is there a way to do this in Javascript/html?
        >
        > I just want to be able to display the results of some calculations on a
        > field that the user inputs as just a label.
        >
        > Thanks,
        >
        > Tom[color=green]
        >>
        >> Thanks,
        >>
        >> Tom
        >>[/color]
        >
        >[/color]


        Comment

        • nutso fasst

          #5
          Re: Problems with ASP.Net object and Javascript


          "tshad" <tscheiderich@f tsolutions.com> wrote in message
          news:OwZ4e.1040 1$FN4.3053@news svr21.news.prod igy.com...[color=blue]
          > Is there a problem setting the span element?[/color]

          A 'value' property on span does not display. The newly-created span element
          is empty and needs to have a text node appended.

          var salaryMinLabel = document.getEle mentById("Salar yMin");
          var sMLText = document.create TextNode("200")
          salaryMinLabel. appendChild(sML Text);
          alert("after setting salaryMinLabel = " +
          salaryMinLabel. firstChild.node Value);

          nf



          Comment

          • tshad

            #6
            Re: Problems with ASP.Net object and Javascript

            "nutso fasst" <no.replies@no. where> wrote in message
            news:db%4e.1043 9$FN4.9079@news svr21.news.prod igy.com...[color=blue]
            >
            > "tshad" <tscheiderich@f tsolutions.com> wrote in message
            > news:OwZ4e.1040 1$FN4.3053@news svr21.news.prod igy.com...[color=green]
            >> Is there a problem setting the span element?[/color]
            >
            > A 'value' property on span does not display. The newly-created span
            > element
            > is empty and needs to have a text node appended.
            >
            > var salaryMinLabel = document.getEle mentById("Salar yMin");
            > var sMLText = document.create TextNode("200")
            > salaryMinLabel. appendChild(sML Text);
            > alert("after setting salaryMinLabel = " +
            > salaryMinLabel. firstChild.node Value);[/color]

            Works great.

            Is there a way to create the child node at the beginning somehow?

            The problem is that as I call this routine It creates another node each
            time. I assume the next time I do the document.getEle mentById("Salar yMin")
            the child node will still be there (since it was appended to the next time I
            did it).

            I am confused as to why or how it is working.

            The 200 is showing on the screen, but when I do a viewsource, it isn't there
            and doesn't seem to be anywhere on the page.

            Here is the script from the viewsource of the page:

            <script language="javas cript1.4">
            function SalaryDisplay(m e)
            {
            alert("this.val ue = " + me.value);
            var salaryMinLabel = document.getEle mentById("Salar yMin");
            var sMLText = document.create TextNode("200")
            salaryMinLabel. appendChild(sML Text);
            SalaryMin2.inne rText = 200;
            alert("after setting salaryMinLabel = " +
            salaryMinLabel. firstChild.node Value);
            }
            </script>

            Here is the html of the label (span):

            &nbsp;&nbsp;Yea rly Compens:<span id="SalaryMin"> </span>&nbsp;/&nbsp;
            <span id="SalaryMax"> </span>

            As you can see there is no 200 there.

            Thanks,

            Tom


            Comment

            • tshad

              #7
              Re: Problems with ASP.Net object and Javascript


              "tshad" <tscheiderich@f tsolutions.com> wrote in message
              news:HHc5e.532$ RQ7.94@newssvr1 4.news.prodigy. com...[color=blue]
              > "nutso fasst" <no.replies@no. where> wrote in message
              > news:db%4e.1043 9$FN4.9079@news svr21.news.prod igy.com...[color=green]
              >>
              >> "tshad" <tscheiderich@f tsolutions.com> wrote in message
              >> news:OwZ4e.1040 1$FN4.3053@news svr21.news.prod igy.com...[color=darkred]
              >>> Is there a problem setting the span element?[/color]
              >>
              >> A 'value' property on span does not display. The newly-created span
              >> element
              >> is empty and needs to have a text node appended.
              >>
              >> var salaryMinLabel = document.getEle mentById("Salar yMin");
              >> var sMLText = document.create TextNode("200")
              >> salaryMinLabel. appendChild(sML Text);
              >> alert("after setting salaryMinLabel = " +
              >> salaryMinLabel. firstChild.node Value);[/color]
              >
              > Works great.
              >
              > Is there a way to create the child node at the beginning somehow?
              >
              > The problem is that as I call this routine It creates another node each
              > time. I assume the next time I do the
              > document.getEle mentById("Salar yMin") the child node will still be there
              > (since it was appended to the next time I did it).
              >
              > I am confused as to why or how it is working.
              >
              > The 200 is showing on the screen, but when I do a viewsource, it isn't
              > there and doesn't seem to be anywhere on the page.
              >
              > Here is the script from the viewsource of the page:
              >
              > <script language="javas cript1.4">
              > function SalaryDisplay(m e)
              > {
              > alert("this.val ue = " + me.value);
              > var salaryMinLabel = document.getEle mentById("Salar yMin");
              > var sMLText = document.create TextNode("200")
              > salaryMinLabel. appendChild(sML Text);
              > SalaryMin2.inne rText = 200;
              > alert("after setting salaryMinLabel = " +
              > salaryMinLabel. firstChild.node Value);
              > }
              > </script>
              >
              > Here is the html of the label (span):
              >
              > &nbsp;&nbsp;Yea rly Compens:<span id="SalaryMin"> </span>&nbsp;/&nbsp;
              > <span id="SalaryMax"> </span>
              >
              > As you can see there is no 200 there.
              >[/color]

              I figured it out.

              I just check to see if the firstchild is null. The script I came up with
              is:

              <script language="javas cript1.4">
              function SalaryDisplay(m e)
              {
              if(me.id == "WagesMin")
              var salaryMinLabel = document.getEle mentById("Salar yMin")
              else
              var salaryMinLabel = document.getEle mentById("Salar yMax");

              if (salaryMinLabel .firstChild == null)
              {
              var sMLText = document.create TextNode("200") ;
              salaryMinLabel. appendChild(sML Text);
              }
              else
              {
              salaryMinLabel. firstChild.node Value = 5;
              }
              }
              </script>

              This works really well for Span tags.

              I have a question on textboxes (input type=text). If I use the above code
              and I put the number 12345 in the textbox and then leave the box - it will
              put the 200 on top of the 12345 (not instead of). It doesn't get rid of the
              12345 before it writes the 200, so the 200 is superimposed ontop of the
              12345.

              When you try to select the text and it is highlighted, only the 12345 shows.
              As soon as you get rid of the selection, then you see the 200 on top of the
              12345 (or whatever you changed it to) again.

              Is this because that the 12345 is the value and the 200 is something else?

              Why is it on top of the 12345 instead of next to it?

              Thanks,

              Tom
              [color=blue]
              > Thanks,
              >
              > Tom
              >
              >[/color]


              Comment

              • tshad

                #8
                Re: Problems with ASP.Net object and Javascript

                Ok.

                This obviously is not going to work. I spent a lot of time getting this
                work correctly and just found that if you go back a page (or forward) and
                then go back to the page - all this SPAN information that was just generated
                is now gone. Probably related to why it doesn't appear in Viewsource.

                Is there a way to make sure it stays with the page?

                Thanks,

                Tom

                "tshad" <tscheiderich@f tsolutions.com> wrote in message
                news:mSd5e.572$ RQ7.168@newssvr 14.news.prodigy .com...[color=blue]
                >
                > "tshad" <tscheiderich@f tsolutions.com> wrote in message
                > news:HHc5e.532$ RQ7.94@newssvr1 4.news.prodigy. com...[color=green]
                >> "nutso fasst" <no.replies@no. where> wrote in message
                >> news:db%4e.1043 9$FN4.9079@news svr21.news.prod igy.com...[color=darkred]
                >>>
                >>> "tshad" <tscheiderich@f tsolutions.com> wrote in message
                >>> news:OwZ4e.1040 1$FN4.3053@news svr21.news.prod igy.com...
                >>>> Is there a problem setting the span element?
                >>>
                >>> A 'value' property on span does not display. The newly-created span
                >>> element
                >>> is empty and needs to have a text node appended.
                >>>
                >>> var salaryMinLabel = document.getEle mentById("Salar yMin");
                >>> var sMLText = document.create TextNode("200")
                >>> salaryMinLabel. appendChild(sML Text);
                >>> alert("after setting salaryMinLabel = " +
                >>> salaryMinLabel. firstChild.node Value);[/color]
                >>
                >> Works great.
                >>
                >> Is there a way to create the child node at the beginning somehow?
                >>
                >> The problem is that as I call this routine It creates another node each
                >> time. I assume the next time I do the
                >> document.getEle mentById("Salar yMin") the child node will still be there
                >> (since it was appended to the next time I did it).
                >>
                >> I am confused as to why or how it is working.
                >>
                >> The 200 is showing on the screen, but when I do a viewsource, it isn't
                >> there and doesn't seem to be anywhere on the page.
                >>
                >> Here is the script from the viewsource of the page:
                >>
                >> <script language="javas cript1.4">
                >> function SalaryDisplay(m e)
                >> {
                >> alert("this.val ue = " + me.value);
                >> var salaryMinLabel = document.getEle mentById("Salar yMin");
                >> var sMLText = document.create TextNode("200")
                >> salaryMinLabel. appendChild(sML Text);
                >> SalaryMin2.inne rText = 200;
                >> alert("after setting salaryMinLabel = " +
                >> salaryMinLabel. firstChild.node Value);
                >> }
                >> </script>
                >>
                >> Here is the html of the label (span):
                >>
                >> &nbsp;&nbsp;Yea rly Compens:<span id="SalaryMin"> </span>&nbsp;/&nbsp;
                >> <span id="SalaryMax"> </span>
                >>
                >> As you can see there is no 200 there.
                >>[/color]
                >
                > I figured it out.
                >
                > I just check to see if the firstchild is null. The script I came up with
                > is:
                >
                > <script language="javas cript1.4">
                > function SalaryDisplay(m e)
                > {
                > if(me.id == "WagesMin")
                > var salaryMinLabel = document.getEle mentById("Salar yMin")
                > else
                > var salaryMinLabel = document.getEle mentById("Salar yMax");
                >
                > if (salaryMinLabel .firstChild == null)
                > {
                > var sMLText = document.create TextNode("200") ;
                > salaryMinLabel. appendChild(sML Text);
                > }
                > else
                > {
                > salaryMinLabel. firstChild.node Value = 5;
                > }
                > }
                > </script>
                >
                > This works really well for Span tags.
                >
                > I have a question on textboxes (input type=text). If I use the above code
                > and I put the number 12345 in the textbox and then leave the box - it will
                > put the 200 on top of the 12345 (not instead of). It doesn't get rid of
                > the 12345 before it writes the 200, so the 200 is superimposed ontop of
                > the 12345.
                >
                > When you try to select the text and it is highlighted, only the 12345
                > shows. As soon as you get rid of the selection, then you see the 200 on
                > top of the 12345 (or whatever you changed it to) again.
                >
                > Is this because that the 12345 is the value and the 200 is something else?
                >
                > Why is it on top of the 12345 instead of next to it?
                >
                > Thanks,
                >
                > Tom
                >[color=green]
                >> Thanks,
                >>
                >> Tom
                >>
                >>[/color]
                >
                >[/color]


                Comment

                • nutso fasst

                  #9
                  Re: Problems with ASP.Net object and Javascript


                  "tshad" <tscheiderich@f tsolutions.com> wrote in message
                  news:FWe5e.2086 1$zl.18682@news svr13.news.prod igy.com...[color=blue]
                  > Is there a way to make sure it stays with the page?[/color]

                  The span tag is being created server-side (runat=server); that is the
                  'source' you view. Content changes you make client-side do not automatically
                  go back to the source, and they are not automatically saved/restored if you
                  switch to another page and then return. You could create a framed site and
                  save all current values for each page in variables in the top frame. I don't
                  know about .net, but suppose there is a database connector. Suggest you try
                  a Microsoft .net newsgroup.

                  nf


                  Comment

                  • RobG

                    #10
                    Re: Problems with ASP.Net object and Javascript

                    tshad wrote:[color=blue]
                    > Ok.
                    >[/color]

                    Please don't top-post - read the group FAQ:

                    <URL:http://www.jibbering.c om/faq/#FAQ2_3>
                    [color=blue]
                    > This obviously is not going to work. I spent a lot of time getting this
                    > work correctly and just found that if you go back a page (or forward) and
                    > then go back to the page - all this SPAN information that was just generated
                    > is now gone. Probably related to why it doesn't appear in Viewsource.[/color]

                    The page source is what was loaded from the server. Whatever you do
                    locally with scripting does not change the source any more than
                    modifying a photocopy changes the original.

                    Some information from history pages may be saved in cache by browsers
                    and used when the page is re-visited, but that mostly applies to data
                    entered into forms fields. Even then, you should not depend on this
                    behaviour being consistent across browsers. I don't think any
                    browser will cache changes made by scripts.
                    [color=blue]
                    >
                    > Is there a way to make sure it stays with the page?[/color]

                    This infers that you wish to maintain state somehow. Various methods
                    exist, such as storing user selections in a cookie or sending data
                    back to the server and then reconstructing the page when the user
                    re-visits. But that takes serious programming effort at both client
                    and server since the web is stateless and you are attempting to make
                    it otherwise.

                    [...]


                    --
                    Rob

                    Comment

                    • tshad

                      #11
                      Re: Problems with ASP.Net object and Javascript

                      "RobG" <rgqld@iinet.ne t.auau> wrote in message
                      news:23l5e.798$ Zn.40681@news.o ptus.net.au...[color=blue]
                      > tshad wrote:[color=green]
                      >> Ok.
                      >>[/color]
                      >
                      > Please don't top-post - read the group FAQ:
                      >
                      > <URL:http://www.jibbering.c om/faq/#FAQ2_3>
                      >[color=green]
                      >> This obviously is not going to work. I spent a lot of time getting this
                      >> work correctly and just found that if you go back a page (or forward) and
                      >> then go back to the page - all this SPAN information that was just
                      >> generated is now gone. Probably related to why it doesn't appear in
                      >> Viewsource.[/color]
                      >
                      > The page source is what was loaded from the server. Whatever you do
                      > locally with scripting does not change the source any more than
                      > modifying a photocopy changes the original.
                      >
                      > Some information from history pages may be saved in cache by browsers
                      > and used when the page is re-visited, but that mostly applies to data
                      > entered into forms fields. Even then, you should not depend on this
                      > behaviour being consistent across browsers. I don't think any
                      > browser will cache changes made by scripts.
                      >[color=green]
                      >>
                      >> Is there a way to make sure it stays with the page?[/color]
                      >
                      > This infers that you wish to maintain state somehow. Various methods
                      > exist, such as storing user selections in a cookie or sending data
                      > back to the server and then reconstructing the page when the user
                      > re-visits. But that takes serious programming effort at both client
                      > and server since the web is stateless and you are attempting to make
                      > it otherwise.[/color]

                      No more that saving what is in the textboxes and which radio buttons that
                      were pushed. If you come back to the page, they are still there. Whatever
                      the SPAN originally was is also still there.

                      If I enter 100 into a text box and then hit the back button and then the
                      forward button, the box still has 100 in it. The 100 wasn't on the original
                      page that was sent. So it is saved somewhere. And not just what the user
                      puts in. I use Javascript to reformat the number to add a "$" and ","s.
                      When I come back, the number is still formatted.

                      But if I create a node for my SPAN in javascript (the same as my changing
                      the formatting in Javascript) to show calculated number as a label, I seem
                      to lose the Node I created. Why is that?

                      Thanks,

                      Tom


                      Comment

                      • RobG

                        #12
                        Re: Problems with ASP.Net object and Javascript

                        tshad wrote:
                        [...][color=blue][color=green]
                        >>[color=darkred]
                        >>>Is there a way to make sure it stays with the page?[/color]
                        >>
                        >> This infers that you wish to maintain state somehow. Various methods
                        >> exist, such as storing user selections in a cookie or sending data
                        >> back to the server and then reconstructing the page when the user
                        >> re-visits. But that takes serious programming effort at both client
                        >> and server since the web is stateless and you are attempting to make
                        >> it otherwise.[/color]
                        >
                        >
                        > No more that saving what is in the textboxes and which radio buttons that
                        > were pushed. If you come back to the page, they are still there. Whatever
                        > the SPAN originally was is also still there.[/color]

                        That's just how browsers work. Back in the good 'ol days, some
                        browsers didn't remember form values either but that was back with
                        Mozaic and Netscape 2 or somewhere back then.

                        I had a few comments on the code you've been posting, the only one of
                        use is in regard to your script tag: ditch the language attribute, it
                        is depreciated and will cause errors in some browsers.

                        You can do what you require if you have a form initialisation
                        function that looks at each form input and if there's something
                        there, runs the onchange if there is one.

                        Below is some sample code for what you are trying to do:

                        <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'
                        'http://www.w3.org/TR/html4/strict.dtd'>
                        <html><head>
                        <title>form thing</title>
                        <meta http-equiv='Content-Type'
                        content='text/html; charset=ISO-8859-1'>
                        <script type="text/javascript">

                        function writeToSpan(t,o ) {
                        if (document.getEl ementById) {
                        o = document.getEle mentById(o);
                        } else if (document.all) {
                        o = document.all[o];
                        }
                        writeIt(t,o);
                        }

                        function writeIt(t,x) {
                        if ( x.firstChild && /\#text/i.test(x.firstC hild.nodeName)) {
                        x.firstChild.da ta = t;
                        } else {
                        if (document.creat eTextNode) {
                        x.appendChild(d ocument.createT extNode(t));
                        }
                        }
                        }

                        function initForm(f){
                        f = document.forms[f];
                        var i = f.length;
                        while (i--) {
                        if (/input/i.test(f[i].nodeName)
                        && /text/i.test(f[i].type)
                        && f[i].onchange
                        && '' != f[i].value){
                        f[i].onchange();
                        }
                        }
                        }

                        </script>
                        </head>
                        <body onload="initFor m('formA');">

                        <form action="" name="formA">
                        <p>Write text to page:
                        <input name="inA" type="text" onchange="
                        writeToSpan(thi s.value,'outA') ;
                        "><span id="outA"></span>
                        <br>
                        Write text to input:
                        <input name="inB" type="text" onchange="
                        this.form.outB. value = this.value;
                        "><input type="text" name="outB">
                        <br><br>
                        <label for="inC">Repla ce this label:
                        <br><input name="inC" id="inC" type="text" onchange="
                        writeIt(this.va lue,this.parent Node);
                        "></label>
                        <br><br>
                        <input type="reset">
                        </p>
                        </form>

                        </body>
                        </html>

                        --
                        Rob

                        Comment

                        • RobG

                          #13
                          Re: Problems with ASP.Net object and Javascript

                          RobG wrote:
                          [...][color=blue]
                          >
                          > function initForm(f){
                          > f = document.forms[f];
                          > var i = f.length;
                          > while (i--) {
                          > if (/input/i.test(f[i].nodeName)
                          > && /text/i.test(f[i].type)
                          > && f[i].onchange
                          > && '' != f[i].value){
                          > f[i].onchange();
                          > }
                          > }
                          > }[/color]

                          Here is a more efficient initForm function:

                          function initForm(f){
                          f = document.forms[f];
                          var x, i = f.length;
                          while ( x = f[--i] ) {
                          if ( /text/i.test(x.type) && x.onchange && '' != x.value){
                          x.onchange();
                          }
                          }
                          }
                          [color=blue]
                          >
                          > </script>
                          > </head>
                          > <body onload="initFor m('formA');">
                          >
                          > <form action="" name="formA">
                          > <p>Write text to page:
                          > <input name="inA" type="text" onchange="
                          > writeToSpan(thi s.value,'outA') ;
                          > "><span id="outA"></span>[/color]

                          And to test that only the onchange() is fired, put this into the form
                          about here:

                          <br>onblur Write text to page:
                          <input name="inD" type="text" onblur="
                          writeToSpan(thi s.value,'outD') ;
                          "><span id="outD"></span>
                          [color=blue]
                          > <br>
                          > Write text to input:
                          > <input name="inB" type="text" onchange="
                          > this.form.outB. value = this.value;
                          > "><input type="text" name="outB">
                          > <br><br>[/color]
                          [...]


                          --
                          Rob

                          Comment

                          • tshad

                            #14
                            Re: Problems with ASP.Net object and Javascript

                            These look pretty good.

                            I need to spend some time to digest them.

                            What does "/input/i.test(f[i].nodeName" and "/text/i.test(f[i].type" mean?

                            What I did on my page was to call the routine I use to create the SPAN label
                            Nodes. Since they are just calculated and formatted from a couple of text
                            fields (which are saved anyway), I just rebuild them from the text boxes.

                            <body class="Applican tBody" onLoad="SalaryD isplayFromOnLoa d()">

                            function SalaryDisplayFr omOnLoad()
                            {
                            var WagesType = document.getEle mentById("Wages Type");
                            SalaryDisplay(W agesType);
                            }

                            This seems to work. But doesn't take into account SPANs that are not
                            calculated from a text field and they only handle these specific labels, not
                            all the labels that might be created, as yours does.

                            Thanks,

                            Tom

                            "RobG" <rgqld@iinet.ne t.auau> wrote in message
                            news:qvn5e.807$ Zn.40816@news.o ptus.net.au...[color=blue]
                            > RobG wrote:
                            > [...][color=green]
                            >>
                            >> function initForm(f){
                            >> f = document.forms[f];
                            >> var i = f.length;
                            >> while (i--) {
                            >> if (/input/i.test(f[i].nodeName)
                            >> && /text/i.test(f[i].type)
                            >> && f[i].onchange
                            >> && '' != f[i].value){
                            >> f[i].onchange();
                            >> }
                            >> }
                            >> }[/color]
                            >
                            > Here is a more efficient initForm function:
                            >
                            > function initForm(f){
                            > f = document.forms[f];
                            > var x, i = f.length;
                            > while ( x = f[--i] ) {
                            > if ( /text/i.test(x.type) && x.onchange && '' != x.value){
                            > x.onchange();
                            > }
                            > }
                            > }
                            >[color=green]
                            >>
                            >> </script>
                            >> </head>
                            >> <body onload="initFor m('formA');">
                            >>
                            >> <form action="" name="formA">
                            >> <p>Write text to page:
                            >> <input name="inA" type="text" onchange="
                            >> writeToSpan(thi s.value,'outA') ;
                            >> "><span id="outA"></span>[/color]
                            >
                            > And to test that only the onchange() is fired, put this into the form
                            > about here:
                            >
                            > <br>onblur Write text to page:
                            > <input name="inD" type="text" onblur="
                            > writeToSpan(thi s.value,'outD') ;
                            > "><span id="outD"></span>
                            >[color=green]
                            >> <br>
                            >> Write text to input:
                            >> <input name="inB" type="text" onchange="
                            >> this.form.outB. value = this.value;
                            >> "><input type="text" name="outB">
                            >> <br><br>[/color]
                            > [...]
                            >
                            >
                            > --
                            > Rob[/color]


                            Comment

                            • tshad

                              #15
                              Re: Problems with ASP.Net object and Javascript


                              "RobG" <rgqld@iinet.ne t.auau> wrote in message
                              news:qvn5e.807$ Zn.40816@news.o ptus.net.au...[color=blue]
                              > RobG wrote:
                              > [...][color=green]
                              >>
                              >> function initForm(f){
                              >> f = document.forms[f];
                              >> var i = f.length;
                              >> while (i--) {
                              >> if (/input/i.test(f[i].nodeName)
                              >> && /text/i.test(f[i].type)
                              >> && f[i].onchange
                              >> && '' != f[i].value){
                              >> f[i].onchange();
                              >> }
                              >> }
                              >> }[/color]
                              >
                              > Here is a more efficient initForm function:
                              >
                              > function initForm(f){
                              > f = document.forms[f];
                              > var x, i = f.length;
                              > while ( x = f[--i] ) {
                              > if ( /text/i.test(x.type) && x.onchange && '' != x.value){
                              > x.onchange();
                              > }
                              > }
                              > }
                              >[color=green]
                              >>
                              >> </script>
                              >> </head>
                              >> <body onload="initFor m('formA');">
                              >>
                              >> <form action="" name="formA">
                              >> <p>Write text to page:
                              >> <input name="inA" type="text" onchange="
                              >> writeToSpan(thi s.value,'outA') ;
                              >> "><span id="outA"></span>[/color]
                              >
                              > And to test that only the onchange() is fired, put this into the form
                              > about here:
                              >
                              > <br>onblur Write text to page:
                              > <input name="inD" type="text" onblur="
                              > writeToSpan(thi s.value,'outD') ;
                              > "><span id="outD"></span>
                              >[/color]
                              I don't quite understant this one?

                              Why is the onblur where it is? I may have misunderstood.

                              Here is what I think you said:

                              *************** *************** *************** *8
                              <form action="" name="formA">
                              <p>Write text to page:
                              <input name="inA" type="text"
                              onchange="write ToSpan(this.val ue,'outA');"><s pan id="outA"></span>

                              <br>onblur Write text to page:
                              <input name="inD" type="text" onblur="
                              writeToSpan(thi s.value,'outD') ;
                              "><span id="outD"></span>

                              <br>
                              Write text to input:<input name="inB" type="text"
                              onchange="this. form.outB.value = this.value;">
                              <input type="text" name="outB">
                              <br><br>
                              <label for="inC">Repla ce this label:<br>
                              <input name="inC" id="inC" type="text"
                              onchange="write It(this.value,t his.parentNode) ;">
                              </label>
                              <br><br>
                              <input type="reset">
                              </p>
                              </form>
                              *************** *************** *************** *************** *****

                              Not sure what that does.

                              Tom
                              [color=blue][color=green]
                              >> <br>
                              >> Write text to input:
                              >> <input name="inB" type="text" onchange="
                              >> this.form.outB. value = this.value;
                              >> "><input type="text" name="outB">
                              >> <br><br>[/color]
                              > [...]
                              >
                              >
                              > --
                              > Rob[/color]


                              Comment

                              Working...