Connecting Tech Pros Worldwide Forums | Help | Site Map

document.images

Jean Pierre Daviau
Guest
 
Posts: n/a
#1: Jul 23 '05

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
Guest
 
Posts: n/a
#2: Jul 23 '05

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.

Jean Pierre Daviau
Guest
 
Posts: n/a
#3: Jul 23 '05

re: document.images


Ha, ha!

And the question is . . .

the [i] does not seem to be red as a number.
alert(totalWidth) 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.



RobB
Guest
 
Posts: n/a
#4: Jul 23 '05

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(totalWidth) 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.images) 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.jpg">
<img src="http://allthatchocolate.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="totalWidth+=this.width;totalHeight+=this.h eight">
<img src="http://www.chrisgilman.com/APPLE_small1.jpg"
onload="totalWidth+=this.width;totalHeight+=this.h eight">
<img src="http://allthatchocolate.com/images/products/apple_small.jpg"
onload="totalWidth+=this.width;totalHeight+=this.h eight">
</script>
</body>
</html>

Jean Pierre Daviau
Guest
 
Posts: n/a
#5: Jul 23 '05

re: document.images


function ready(){
var largeur = screen.availWidth;
var hauteur = screen.availHeight;
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(totalWidth); ============0
}

<body onLoad="ready()">


J. J. Cale
Guest
 
Posts: n/a
#6: Jul 23 '05

re: document.images



"Jean Pierre Daviau" <Once@WasEno.ugh> wrote in message
news:mV88e.105039$db3.1683708@wagner.videotron.net ...[color=blue]
> function ready(){
> var largeur = screen.availWidth;
> var hauteur = screen.availHeight;
> 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(totalWidth); ============0
> }
>
> <body onLoad="ready()">
>
>[/color]


Jean Pierre Daviau
Guest
 
Posts: n/a
#7: Jul 23 '05

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@netvision.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 ?




Richard Cornford
Guest
 
Posts: n/a
#8: Jul 23 '05

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.availWidth/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.


Jean Pierre Daviau
Guest
 
Posts: n/a
#9: Jul 23 '05

re: document.images



"Richard Cornford" <Richard@litotes.demon.co.uk> a écrit dans le message de
news: d3tkia$l1a$1$8300dec7@news.demon.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.availWidth/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


Closed Thread