document.images

J

Jean Pierre Daviau

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

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

RobB

Jean said:
for (var i=0; i< document.images.lenght; i++){

'lenght' ? (sp)
totalWidth = totalWidth + document.images.width;
totalHeight = totalHeight + document.images.height;


totalWidth += document.images.width;
totalHeight += document.images.height;
}
--

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

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

Jean Pierre Daviau

Ha, ha!

And the question is . . .

the does not seem to be red as a number.
alert(totalWidth) gives 0.
We will now consult the oracle, hoping to divine your question.

After all it is signed
X treme newbe

Thank you for reading.
 
R

RobB

Jean said:
Ha, ha!

And the question is . . .

the does not seem to be red as a number.
alert(totalWidth) gives 0.
We will now consult the oracle, hoping to divine your question.

After all it is signed
X treme newbe

Thank you for reading.


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

Jean Pierre Daviau

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.width;
totalHeight = totalHeight + document.images.height;
}


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

<body onLoad="ready()">
 
J

J. J. Cale

Jean Pierre Daviau said:
function ready(){
var largeur = screen.availWidth;
var hauteur = screen.availHeight;
var n = document.images.lenght;

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

var totalWidth = 0;
var totalHeight = 0;

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


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

<body onLoad="ready()">
 
J

Jean Pierre Daviau

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" <[email protected]> a écrit dans le message de 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 ?
 
R

Richard Cornford

Jean said:
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.
 
J

Jean Pierre Daviau

"Richard Cornford" <[email protected]> a écrit dans le message de
[email protected]...
| 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

document.images[0].X 6
circle tracing 10
javascript corrupted? 8
meta for two languages 3
location.replace in a function 10
running an ex on eMac 8
changing the barckground image 2
loading order 2

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top