473,396 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Jul 23 '05 #1
8 2493
Jean Pierre Daviau wrote:
for (var i=0; i< document.images.lenght; i++){
'lenght' ? (sp)
totalWidth = totalWidth + document.images[i].width;
totalHeight = totalHeight + document.images[i].height;
totalWidth += document.images[i].width;
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


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

Jul 23 '05 #2
Ha, ha!

And the question is . . .

the [i] 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.

Jul 23 '05 #3
Jean Pierre Daviau wrote:
Ha, ha!

And the question is . . .

the [i] 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[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>

Jul 23 '05 #4
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()">
Jul 23 '05 #5

"Jean Pierre Daviau" <On**@WasEno.ugh> wrote in message
news:mV**********************@wagner.videotron.net ...
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[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()">

Jul 23 '05 #6
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" <ph****@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 ?


Jul 23 '05 #7
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.
Jul 23 '05 #8

"Richard Cornford" <Ri*****@litotes.demon.co.uk> a écrit dans le message de
news: d3*******************@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
Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Winfried Koenig | last post by:
Hi everyone, I have a main page: -------------------------------------------------- <html><head><title>Test</title> </head><body> <img id="img_a" name="img_a" src="image_1.png" alt=""><br>
2
by: Aaron | last post by:
Hi, I've seen javascript code where a constructor function is passed an argument "document", and inside the function itself the assignment "this.document = document;" is made. This is the code...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
9
by: Jeff | last post by:
I get the following error when I try to rollover my button: document.images has no properties Line: 22 Am I doing this correctly? Suggestions? This is using Netscape 7.2 on Fedora core 4. ...
6
by: Bob Alston | last post by:
I am looking for others who have built systems to scan documents, index them and then make them accessible from an Access database. My environment is a nonprofit with about 20-25 case workers who...
6
by: Rob | last post by:
Hello, I'm sure this has come up before. I have need for a collection of all elements/objects in an HTML document that have any kind of an attribute (HTML or CSS) that is making use of a URL to...
7
by: Draenox | last post by:
In an if statement with "document.images" as it's expression, does it simply check if there are any image elements in an HTML page? I'm assuming if it finds any that the expression will return true...
4
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
10
by: AC | last post by:
I had a page that does some event setup on window.onload: function prepEvents() { document.getElementById("menumap_sales").onmouseover = swapMenuSales; // etc } window.onload = prepEvents;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.