children["id"].innerText - does not work with netscape but with explorer

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

    children["id"].innerText - does not work with netscape but with explorer

    I have a function that works with explorer but not with netscape.
    The problem is the function at line 5.


    1 fSetSelectedDay (myElement){
    2 /*
    3 ...
    4 */
    5 var elementText = eval(myElement. children["calDateTex t"].innerText);
    6 /*
    7 ...
    8 */
    9 }
    10 <!-- ... -->
    11 <td id=calCell onclick='fSetSe lectedDay(this) '>
    12 <font id='calDateText ' onclick='fSetSe lectedDay(this) '>
    13 <script> myMonth[w][d] </script>
    14 </font>
    15 </td>
    16 <!-- ... -->


    I need some support for this.
    Thank you very much.
  • Randy Webb

    #2
    Re: children[&quot;id&quo t;].innerText - does not work with netscape but withexplorer

    Julia Peterwitz wrote:[color=blue]
    > I have a function that works with explorer but not with netscape.
    > The problem is the function at line 5.
    >
    >
    > 1 fSetSelectedDay (myElement){
    > 2 /*
    > 3 ...
    > 4 */
    > 5 var elementText = eval(myElement. children["calDateTex t"].innerText);[/color]

    ..innerText is IE only, and as such is not going to work in NS. use
    innerHTML instead.

    eval is not needed there:

    var elementText =
    document.getEle mentById(myElem ent).children(' calDateText').i nnerHTML;

    the [ ] are also an IE-ism.



    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • Michael Winter

      #3
      Re: children[&quot;id&quo t;].innerText - does not work with netscape but with explorer

      On Wed, 05 May 2004 06:41:28 -0400, Randy Webb <hikksnotathome @aol.com>
      wrote:
      [color=blue]
      > Julia Peterwitz wrote:[color=green]
      >> I have a function that works with explorer but not with netscape.
      >> The problem is the function at line 5.
      >>
      >>
      >> 1 fSetSelectedDay (myElement){
      >> 2 /*
      >> 3 ...
      >> 4 */
      >> 5 var elementText = eval(myElement. children["calDateTex t"].innerText);[/color]
      >
      > .innerText is IE only, and as such is not going to work in NS. use
      > innerHTML instead.
      >
      > eval is not needed there:[/color]

      Agreed, however...
      [color=blue]
      > var elementText =
      > document.getEle mentById(myElem ent).children(' calDateText').i nnerHTML;[/color]

      ....there are two problems with this line:

      1) If you look at the OP's HTML, you'll see that myElement is a
      reference to the element, not an id.
      2) The children property is
      a) a collection, so the brackets were correct,
      b) also a Microsoft-ism.

      Perhaps

      var elementText = myElement.child Nodes[ 'calDateText' ].innerHTML;

      would be better (preferably with feature detection)?

      Mike

      --
      Michael Winter
      M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

      Comment

      • julia peterwitz

        #4
        Re: children[&quot;id&quo t;].innerText - does not work with netscape but with explorer

        myElement.child Nodes[ 'calDateText' ].innerHTML;
        is also not working
        (it neither works in explorer nor in netscape)

        any other proposals for netscape??

        solution for explorer again:
        myElement.child ren["calDateTex t"].innerText;

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Michael Winter

          #5
          Re: children[&quot;id&quo t;].innerText - does not work with netscape but with explorer

          On 05 May 2004 16:37:14 GMT, julia peterwitz <pi.ti@gmx.de > wrote:
          [color=blue]
          > myElement.child Nodes[ 'calDateText' ].innerHTML;
          > is also not working
          > (it neither works in explorer nor in netscape)
          >
          > any other proposals for netscape??[/color]

          Oops. I assumed that childNodes was a standard collection that could be
          indexed by name/id as well as ordinal. However, I just thought that
          'calDateText' is an id, so why don't you just use

          document.getEle mentById( 'calDateText' ).innerHTML

          ?

          Mike

          --
          Michael Winter
          M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: children[&quot;id&quo t;].innerText - does not work with netscape but withexplorer

            pi-ti@gmx.de (Julia Peterwitz) writes:
            [color=blue]
            > I have a function that works with explorer but not with netscape.
            > The problem is the function at line 5.[/color]

            You don't say which Netscape. If it's Netscape 4, your options are
            very limited. If it's Netscape 6+, i.e., based on Mozilla, then
            you can pretty much fly :) I'll assume Netscape 6+.
            [color=blue]
            > 5 var elementText = eval(myElement. children["calDateTex t"].innerText);[/color]

            I see three problems:
            - innerText is IE only.
            - children is IE only.
            - eval is evil.

            There are different options, depending on how standards compliant you
            want to be. I'll go for full compliance with the DOM specification
            (i.e., avoiding innerHTML).

            A version that collects the string content of the calcDateText element
            (not recursively, so don't put the text to find inside tags).
            ---
            var span = document.getEle mentById("calcD ateText");
            var elementText = "";
            for(var chld = span.firstChild ; chld; chdl=chld.nextS ibling) {
            if (chld.nodeType == 3) { // text node
            elementText += chld.nodeValue;
            }
            }
            ---
            Or, change the first line to:
            ---
            var span = myElement.getEl ementsByTagName ("span")[0];
            ---
            (Notice that I use "span" instead of "font" as commented later)
            [color=blue]
            > 11 <td id=calCell onclick='fSetSe lectedDay(this) '>
            > 12 <font id='calDateText ' onclick='fSetSe lectedDay(this) '>[/color]

            The font tag is deprecated and you are not using any of its specific
            attributes anyway. Change it to a <span> instead, that is just what
            you need: a meaningless wrapper.
            [color=blue]
            > 13 <script> myMonth[w][d] </script>[/color]

            The type attribute is required on script tags, so:
            ---
            <script type="text/javascript">
            ---
            Do you mean to document.write the value?
            ---
            document.write( myMonth[w][d]));
            ---
            Where are "w" and "d" calculated? (Meaning Week and Day?)
            [color=blue]
            > 14 </font>[/color]
            </span>

            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Julia Peterwitz

              #7
              Re: children[&quot;id&quo t;].innerText - does not work with netscape but with explorer

              Lasse Reichstein Nielsen <lrn@hotpop.com > wrote in message news:<hduu4vcs. fsf@hotpop.com> ...[color=blue]
              > pi-ti@gmx.de (Julia Peterwitz) writes:
              >[color=green]
              > > I have a function that works with explorer but not with netscape.
              > > The problem is the function at line 5.[/color]
              >
              > You don't say which Netscape. If it's Netscape 4, your options are
              > very limited. If it's Netscape 6+, i.e., based on Mozilla, then
              > you can pretty much fly :) I'll assume Netscape 6+.[/color]

              yes, I thought about netscape 6+
              [color=blue]
              >[color=green]
              > > 5 var elementText = eval(myElement. children["calDateTex t"].innerText);[/color]
              >
              > I see three problems:
              > - innerText is IE only.
              > - children is IE only.
              > - eval is evil.
              >
              > There are different options, depending on how standards compliant you
              > want to be. I'll go for full compliance with the DOM specification
              > (i.e., avoiding innerHTML).
              >
              > A version that collects the string content of the calcDateText element
              > (not recursively, so don't put the text to find inside tags).
              > ---
              > var font= myElement.getEl ementsByTagName ("font");
              > var elementText = "";[/color]

              until here it works.
              but the following doesn't start.
              and I don't know why.
              but there is no error message.
              [color=blue]
              > for(var chld = font.firstChild ; chld; chdl=chld.nextS ibling) {
              > if (chld.nodeType == 3) { // text node
              > elementText += chld.nodeValue;
              > }
              > }
              > ---
              >[color=green]
              > > 11 <td id=calCell onclick='fSetSe lectedDay(this) '>
              > > 12 <font id='calDateText ' onclick='fSetSe lectedDay(this) '>[/color]
              >
              > The font tag is deprecated and you are not using any of its specific
              > attributes anyway. Change it to a <span> instead, that is just what
              > you need: a meaningless wrapper.[/color]

              I removed the irrelevant attributes.
              so I will use <font> further on.
              [color=blue]
              >[color=green]
              > > 13 <script> myMonth[w][d] </script>[/color]
              >
              > The type attribute is required on script tags, so:
              > ---
              > <script type="text/javascript">
              > ---
              > Do you mean to document.write the value?
              > ---
              > document.write( myMonth[w][d]));[/color]

              sorry I forgot to put the document.write around

              13 <script> document.write( myMonth[w][d]); </script>

              this function notes the days of the months, but this is irrelevant for
              the problem. isn't it?
              [color=blue]
              > ---
              > Where are "w" and "d" calculated? (Meaning Week and Day?)
              >[color=green]
              > > 14 </font>[/color]
              > </span>
              >
              > /L[/color]

              Comment

              • Lasse Reichstein Nielsen

                #8
                Re: children[&quot;id&quo t;].innerText - does not work with netscape but withexplorer

                pi-ti@gmx.de (Julia Peterwitz) writes:
                [color=blue]
                > Lasse Reichstein Nielsen <lrn@hotpop.com > wrote in message news:<hduu4vcs. fsf@hotpop.com> ...[color=green]
                >> var font= myElement.getEl ementsByTagName ("font");
                >> var elementText = "";[/color]
                >
                > until here it works.
                > but the following doesn't start.
                > and I don't know why.
                > but there is no error message.
                >[color=green]
                >> for(var chld = font.firstChild ; chld; chdl=chld.nextS ibling) {[/color][/color]

                Damn! :(
                That would be the typo: ^^^^ shoud be chld.

                That would mean that the loop goes on forever ... doing nothing.

                /L
                --
                Lasse Reichstein Nielsen - lrn@hotpop.com
                DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                'Faith without judgement merely degrades the spirit divine.'

                Comment

                • Julia Peterwitz

                  #9
                  Re: children[&quot;id&quo t;].innerText - does not work with netscape but with explorer

                  /*
                  ....
                  */

                  alert("1");
                  var font = myElement.getEl ementsByTagName ("font");
                  alert("2");
                  var elementText = "";
                  alert("3");
                  for(var chld = font.firstChild ; chld; chld=chld.nextS ibling) {
                  alert("4");
                  if (chld.nodeType == 3) { // text node
                  elementText += chld.nodeValue;
                  }

                  /*
                  ....
                  */

                  when I start this I'll get the alert's 1,2,3 but the alert 4 doesn't start.
                  so I think there is something wrong.
                  but I don't know what.

                  Comment

                  • Julia Peterwitz

                    #10
                    Re: children[&quot;id&quo t;].innerText - does not work with netscape but with explorer

                    Michael Winter <M.Winter@bluey onder.co.invali d> wrote in message news:<opr7jdg3o l5vklcq@news-text.blueyonder .co.uk>...[color=blue]
                    > On 05 May 2004 16:37:14 GMT, julia peterwitz <pi.ti@gmx.de > wrote:
                    >[color=green]
                    > > myElement.child Nodes[ 'calDateText' ].innerHTML;
                    > > is also not working
                    > > (it neither works in explorer nor in netscape)
                    > >
                    > > any other proposals for netscape??[/color]
                    >
                    > Oops. I assumed that childNodes was a standard collection that could be
                    > indexed by name/id as well as ordinal. However, I just thought that
                    > 'calDateText' is an id, so why don't you just use
                    >
                    > document.getEle mentById( 'calDateText' ).innerHTML
                    >
                    > ?
                    >
                    > Mike[/color]


                    elementText = document.getEle mentById('calDa teText').innerH TML;
                    alert(elementTe xt);

                    good idea, but elementText is "".
                    do you know why?

                    Comment

                    • ZER0

                      #11
                      Re: children[&quot;id&quo t;].innerText - does not work with netscape but with explorer

                      On 7 May 2004 01:44:12 -0700, Julia Peterwitz wrote:
                      [color=blue]
                      > elementText = document.getEle mentById('calDa teText').innerH TML;
                      > alert(elementTe xt);[/color]
                      [color=blue]
                      > good idea, but elementText is "".
                      > do you know why?[/color]

                      Try something like that:

                      <script type="text/javascript">
                      function getInnerText(el ){
                      return
                      el.innerHTML.re place(/(<script[^>]*?>.*?<\/script>)|[\r\n]/gi,"").replace (/<[\/\!]*?[^<>]*?>/g,"");
                      }

                      function fSetSelectedDay (el){
                      alert(">"+getIn nerText(el)+"<" );
                      }
                      </script>

                      <font id='calDateText '
                      onclick='fSetSe lectedDay(this) '><script>docum ent.write('some text,<br />
                      maybe with <strong>tags</strong>');</script></font>

                      I hope it helps.


                      --
                      C'ya,
                      ZER0 :: coder.gfxer.web Designer();

                      Il computer e' una macchina progettata per velocizzare e automatizzare
                      gli errori.

                      Comment

                      • Michael Winter

                        #12
                        Re: children[&quot;id&quo t;].innerText - does not work with netscape but with explorer

                        On 7 May 2004 01:44:12 -0700, Julia Peterwitz <pi-ti@gmx.de> wrote:

                        [snip]
                        [color=blue]
                        > elementText = document.getEle mentById('calDa teText').innerH TML;
                        > alert(elementTe xt);
                        >
                        > good idea, but elementText is "".
                        > do you know why?[/color]

                        Not a clue. Can you post a complete sample (preferably a URL)?

                        Mike

                        --
                        Michael Winter
                        M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

                        Comment

                        • Julia Peterwitz

                          #13
                          Re: children[&quot;id&quo t;].innerText - does not work with netscape but with explorer

                          Michael Winter <M.Winter@bluey onder.co.invali d> wrote in message news:<opr7mm0xg c5vklcq@news-text.blueyonder .co.uk>...[color=blue]
                          > On 7 May 2004 01:44:12 -0700, Julia Peterwitz <pi-ti@gmx.de> wrote:
                          >
                          > [snip]
                          >[color=green]
                          > > elementText = document.getEle mentById('calDa teText').innerH TML;
                          > > alert(elementTe xt);
                          > >
                          > > good idea, but elementText is "".
                          > > do you know why?[/color]
                          >
                          > Not a clue. Can you post a complete sample (preferably a URL)?
                          >
                          > Mike[/color]

                          This website is for sale! fligo.de is your first and best source for all of the information you’re looking for. From general topics to more of what you would expect to find here, fligo.de has it all. We hope you find what you are searching for!

                          is the url for the script


                          is the url for the page

                          Comment

                          • Thomas 'PointedEars' Lahn

                            #14
                            Re: children[&quot;id&quo t;].innerText - does not work with netscape but withexplorer

                            Julia Peterwitz wrote:
                            [color=blue]
                            > alert("1");
                            > var font = myElement.getEl ementsByTagName ("font");
                            > alert("2");
                            > var elementText = "";
                            > alert("3");
                            > for(var chld = font.firstChild ; chld; chld=chld.nextS ibling) {[/color]
                            ^[color=blue]
                            > alert("4");
                            > if (chld.nodeType == 3) { // text node[/color]
                            ^[color=blue]
                            > elementText += chld.nodeValue;
                            > }[/color]
                            ^[color=blue]
                            > /*
                            > ...
                            > */
                            >
                            > when I start this I'll get the alert's 1,2,3 but the alert 4 doesn't start.
                            > so I think there is something wrong.
                            > but I don't know what.[/color]

                            Looks like there is a closing brace missing. Does the JavaScript
                            Console tell you anything? If yes, what does it say?


                            PointedEars

                            Comment

                            Working...