document.images

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jean Pierre Daviau

    #1

    document.images


    for (var i=0; i< document.images .lenght; i++){
    totalWidth = totalWidth + document.images[i].width;
    totalHeight = totalHeight + document.images[i].height;
    }
    --

    X trême newbe
    .......
    masm32
    windows Xp
    asus p4 s533/333/133
    Intel(R) Celeron (R) CPU 2.00 GHz


  • RobB

    #2
    Re: document.images

    Jean Pierre Daviau wrote:[color=blue]
    > for (var i=0; i< document.images .lenght; i++){[/color]

    'lenght' ? (sp)
    [color=blue]
    > totalWidth = totalWidth + document.images[i].width;
    > totalHeight = totalHeight + document.images[i].height;[/color]

    totalWidth += document.images[i].width;
    totalHeight += document.images[i].height;
    [color=blue]
    > }
    > --
    >
    > X trême newbe
    > ......
    > masm32
    > windows Xp
    > asus p4 s533/333/133
    > Intel(R) Celeron (R) CPU 2.00 GHz[/color]

    We will now consult the oracle, hoping to divine your question.

    Comment

    • Jean Pierre Daviau

      #3
      Re: document.images

      Ha, ha!

      And the question is . . .

      the [i] does not seem to be red as a number.
      alert(totalWidt h) gives 0.
      [color=blue]
      > We will now consult the oracle, hoping to divine your question.[/color]

      After all it is signed
      X treme newbe

      Thank you for reading.



      Comment

      • RobB

        #4
        Re: document.images

        Jean Pierre Daviau wrote:[color=blue]
        > Ha, ha!
        >
        > And the question is . . .
        >
        > the [i] does not seem to be red as a number.
        > alert(totalWidt h) gives 0.
        >[color=green]
        > > We will now consult the oracle, hoping to divine your question.[/color]
        >
        > After all it is signed
        > X treme newbe
        >
        > Thank you for reading.[/color]

        Now there's a problème !

        Always post as much of what you're doing as seems reasonable. Are you
        running this script in the <head>er of the document? Source files are
        read from beginning-to-end (top to bottom as they appear in your
        editor). Can't rummage through a collection (document.image s) that
        hasn't been made yet. Always hook these up to an onload handler:

        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
        <html>
        <head>
        <script type="text/javascript">

        function getImageDims()
        {
        var totalWidth = totalHeight = 0;
        for (var i = 0; i < document.images .length; i++)
        {
        totalWidth += document.images[i].width;
        totalHeight += document.images[i].height;
        }
        alert('total width: ' + totalWidth + '\ntotal height: ' +
        totalHeight);
        }

        window.onload = getImageDims; //no ()!

        </script>
        </head>
        <body>
        <img src="http://www.4girls.gov/nutrition/apple-small.jpg">
        <img src="http://www.chrisgilman .com/APPLE_small1.jp g">
        <img src="http://allthatchocolat e.com/images/products/apple_small.jpg ">
        </script>
        </body>
        </html>

        Image objects have their own onload handlers (like the window, above -
        so:

        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
        <html>
        <head>
        <script type="text/javascript">

        var totalWidth = totalHeight = 0;

        function getImageDims()
        {
        alert('total width: ' + totalWidth + '\ntotal height: ' +
        totalHeight);
        }

        window.onload = getImageDims;

        </script>
        </head>
        <body>
        <img src="http://www.4girls.gov/nutrition/apple-small.jpg"
        onload="totalWi dth+=this.width ;totalHeight+=t his.height">
        <img src="http://www.chrisgilman .com/APPLE_small1.jp g"
        onload="totalWi dth+=this.width ;totalHeight+=t his.height">
        <img src="http://allthatchocolat e.com/images/products/apple_small.jpg "
        onload="totalWi dth+=this.width ;totalHeight+=t his.height">
        </script>
        </body>
        </html>

        Comment

        • Jean Pierre Daviau

          #5
          Re: document.images

          function ready(){
          var largeur = screen.availWid th;
          var hauteur = screen.availHei ght;
          var n = document.images .lenght;
          var totalWidth = 0;
          var totalHeight = 0;

          for (var i=0; i< n; i++){
          totalWidth = totalWidth + document.images[i].width;
          totalHeight = totalHeight + document.images[i].height;
          }


          var wspacer = (largeur/totalWidth)/(n+1);
          var hspacer = (hauteur/totalHeight)/(n+1);
          alert(wspacer); ============NaN
          alert(totalWidt h); ============0
          }

          <body onLoad="ready() ">


          Comment

          • J. J. Cale

            #6
            Re: document.images


            "Jean Pierre Daviau" <Once@WasEno.ug h> wrote in message
            news:mV88e.1050 39$db3.1683708@ wagner.videotro n.net...[color=blue]
            > function ready(){
            > var largeur = screen.availWid th;
            > var hauteur = screen.availHei ght;
            > var n = document.images .lenght;[/color]

            var n = document.images .length;
            I suspect this typo has been persisting since the original post

            [color=blue]
            > var totalWidth = 0;
            > var totalHeight = 0;
            >
            > for (var i=0; i< n; i++){
            > totalWidth = totalWidth + document.images[i].width;
            > totalHeight = totalHeight + document.images[i].height;
            > }
            >
            >
            > var wspacer = (largeur/totalWidth)/(n+1);
            > var hspacer = (hauteur/totalHeight)/(n+1);
            > alert(wspacer); ============NaN
            > alert(totalWidt h); ============0
            > }
            >
            > <body onLoad="ready() ">
            >
            >[/color]


            Comment

            • Jean Pierre Daviau

              #7
              Re: document.images

              My second post with the question dissapeared somewhere.

              I am posting with OutlookExpress. Is there a problem with that on the
              newsgroup server?

              "J. J. Cale" <photom@netvisi on.net.il> a écrit dans le message de news:
              4261e043
              | var n = document.images .length;
              | I suspect this typo has been persisting since the original post



              If I write alert(document. images[0].width+document .images[1].width) it gives
              271 . Witch is OK.

              If I use a for loop, I get 0. Why ?




              Comment

              • Richard Cornford

                #8
                Re: document.images

                Jean Pierre Daviau wrote:[color=blue]
                > My second post with the question dissapeared somewhere.[/color]

                Try putting the question in the same post as the code.
                [color=blue]
                > I am posting with OutlookExpress. Is there a problem with
                > that on the newsgroup server?[/color]

                Outlook express can be successfully used for posting to newsgroups,
                though it probably takes more effort on the part of its users to get the
                posting format correct than some of the alternatives.
                [color=blue]
                > J. J. Cale wrote:
                >| var n = document.images .length;
                >| I suspect this typo has been persisting since the original
                >| post
                >
                > If I write alert(document. images[0].width+document .images[1].width)
                > it gives 271 . Witch is OK.
                >
                > If I use a for loop, I get 0. Why ?[/color]

                The point that J.J.Cale is making is that "lenght" is a misspelling of
                "length" and as the form will not have a "lenght" property the - n -
                variable will be assigned the value - undefined -. Then when - i < n -
                is evaluated (where - i - is numeric) - n - will be type-converted to a
                number, and that number is NaN. All comparisons with NaN return false so
                the body of the - for - loop is never executed and the - totalWidth -
                and - totalHeight - variables retain the value to which they were
                initialised; zero.

                On the whole the scheme seems potty though. There is no useful
                relationship between the screen.availWid th/Height values and anything
                that happens within the viewport of a web browser (not even that the
                dimensions of the viewport will be less than the avialWidth/Height).

                Richard.


                Comment

                • Jean Pierre Daviau

                  #9
                  Re: document.images


                  "Richard Cornford" <Richard@litote s.demon.co.uk> a écrit dans le message de
                  news: d3tkia$l1a$1$83 00dec7@news.dem on.co.uk...
                  | Jean Pierre Daviau wrote:
                  | > My second post with the question dissapeared somewhere.
                  |
                  | Try putting the question in the same post as the code.
                  |
                  | > I am posting with OutlookExpress. Is there a problem with
                  | > that on the newsgroup server?
                  |
                  | Outlook express can be successfully used for posting to newsgroups,
                  | though it probably takes more effort on the part of its users to get the
                  | posting format correct than some of the alternatives.
                  |
                  | > J. J. Cale wrote:
                  | >| var n = document.images .length;
                  | >| I suspect this typo has been persisting since the original
                  | >| post
                  | >
                  | > If I write alert(document. images[0].width+document .images[1].width)
                  | > it gives 271 . Witch is OK.
                  | >
                  | > If I use a for loop, I get 0. Why ?
                  |
                  | The point that J.J.Cale is making is that "lenght" is a misspelling of
                  | "length" and as the form will not have a "lenght" property the - n -
                  | variable will be assigned the value - undefined -. Then when - i < n -
                  | is evaluated (where - i - is numeric) - n - will be type-converted to a
                  | number, and that number is NaN. All comparisons with NaN return false so
                  | the body of the - for - loop is never executed and the - totalWidth -
                  | and - totalHeight - variables retain the value to which they were
                  | initialised; zero.
                  |
                  | On the whole the scheme seems potty though. There is no useful
                  | relationship between the screen.availWid th/Height values and anything
                  | that happens within the viewport of a web browser (not even that the
                  | dimensions of the viewport will be less than the avialWidth/Height).
                  |
                  | Richard.
                  Thank you very much


                  Comment

                  Working...