this should be an array 
Author Message
 this should be an array

i already posted this as a separate article on another newsgroup, but it
didn't look like a very active group, so i am posting it again here.
*sincere* apologies for my breach of netiquette, but i need help with
this...  thanks!
Quote:

> i hope this is the right newsgroup.  this is a client-side javascript
> question.

> why doesn't the code below work?

> <html>

> <head>
>  <script language="javascript">
>  <!--
>  function do_func() {

>   // i wouldn't think this would work, since photo should be an array
>   alert(document.images["photo"].src);

>   // i would think this would work, since photo should be an array
>   alert(document.images["photo"].length);

>   return true;
>  }
>  //-->
>  </script>
> </head>

> <body>

> <!-- notice both images have the same name -->
> <!-- when i do this with form elements, i get an array when accessing them
> via javascript -->
> <img name="photo" onclick="return do_func()" border="1"
> src="../images/white_pixel.gif" width="100" height="100">
> <img name="photo" onclick="return do_func()" border="1"
> src="../images/black_pixel.gif" width="100" height="100">

> </body>
> </html>

> thanks!

> --
> Doug Bass
> Senior Web Developer



Sun, 29 Aug 2004 11:50:04 GMT  
 this should be an array
photo would NOT be an array.

the second "photo" image would overwrite the first in the
document.images array. images are not radiobuttons. each one needs a
unique name.

Atrax - MVP [Microsoft Most Valued Professional]

http://www.infinitemonkeys.ws/

Host with me for $100 a year!
http://www.atrax.ws/hosting/

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



Sun, 29 Aug 2004 12:07:29 GMT  
 this should be an array
that makes sense with what i am seeing.  i wish images behaved like form
elements, and could be accessed via an array when their names are not
unique.  thanks for the response.


Quote:
> photo would NOT be an array.

> the second "photo" image would overwrite the first in the
> document.images array. images are not radiobuttons. each one needs a
> unique name.

> Atrax - MVP [Microsoft Most Valued Professional]

> http://www.infinitemonkeys.ws/

> Host with me for $100 a year!
> http://www.atrax.ws/hosting/

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



Sun, 29 Aug 2004 12:16:17 GMT  
 this should be an array
"i wish images behaved like form elements"

why? I don't. you can access them by index if you really need to

document.images[0]
document.images[1]

and so on. images are all essentially the same, so there's no point
allowing them to go all two-dimensional - it's just added complication
where it's not required. it's not like they have values as radio buttons
do.

Atrax - MVP [Microsoft Most Valued Professional]

http://www.infinitemonkeys.ws/

Host with me for $100 a year!
http://www.atrax.ws/hosting/

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



Sun, 29 Aug 2004 12:27:31 GMT  
 this should be an array
pls don't make a blanket statements like "there's no point allowing them to
go all two-dimensional".  you have no idea what i'm trying to do.  the way
my mind works, and the way the page is laid out, it makes perfect sense.


Quote:
> "i wish images behaved like form elements"

> why? I don't. you can access them by index if you really need to

> document.images[0]
> document.images[1]

> and so on. images are all essentially the same, so there's no point
> allowing them to go all two-dimensional - it's just added complication
> where it's not required. it's not like they have values as radio buttons
> do.

> Atrax - MVP [Microsoft Most Valued Professional]

> http://www.infinitemonkeys.ws/

> Host with me for $100 a year!
> http://www.atrax.ws/hosting/

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



Sun, 29 Aug 2004 12:47:00 GMT  
 this should be an array
Have you tried a reference via document.all["photo"] assuming only <img> elements have the name "photo"?

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:

> pls don't make a blanket statements like "there's no point allowing them to
> go all two-dimensional".  you have no idea what i'm trying to do.  the way
> my mind works, and the way the page is laid out, it makes perfect sense.



> > "i wish images behaved like form elements"

> > why? I don't. you can access them by index if you really need to

> > document.images[0]
> > document.images[1]

> > and so on. images are all essentially the same, so there's no point
> > allowing them to go all two-dimensional - it's just added complication
> > where it's not required. it's not like they have values as radio buttons
> > do.

> > Atrax - MVP [Microsoft Most Valued Professional]

> > http://www.infinitemonkeys.ws/

> > Host with me for $100 a year!
> > http://www.atrax.ws/hosting/

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



Sun, 29 Aug 2004 12:52:59 GMT  
 this should be an array
how did you get to be an mvp with that attitude?  i didn't miss your point.


Quote:
> you missed my point altogether there, but i'll let you carry on as you
> wish. I really can't be bothered.

> Atrax - MVP [Microsoft Most Valued Professional]

> http://www.infinitemonkeys.ws/

> Host with me for $100 a year!
> http://www.atrax.ws/hosting/

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



Sun, 29 Aug 2004 19:54:52 GMT  
 this should be an array
that worked!  thanks a million!  i guess i'll need to see how to make it
work in netscape next ;)

doug



Have you tried a reference via document.all["photo"] assuming only <img>
elements have the name "photo"?

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:
> pls don't make a blanket statements like "there's no point allowing them
to
> go all two-dimensional".  you have no idea what i'm trying to do.  the way
> my mind works, and the way the page is laid out, it makes perfect sense.



> > "i wish images behaved like form elements"

> > why? I don't. you can access them by index if you really need to

> > document.images[0]
> > document.images[1]

> > and so on. images are all essentially the same, so there's no point
> > allowing them to go all two-dimensional - it's just added complication
> > where it's not required. it's not like they have values as radio buttons
> > do.

> > Atrax - MVP [Microsoft Most Valued Professional]

> > http://www.infinitemonkeys.ws/

> > Host with me for $100 a year!
> > http://www.atrax.ws/hosting/

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



Sun, 29 Aug 2004 19:58:04 GMT  
 this should be an array

Quote:

> that worked!  thanks a million!  i guess i'll need to see how to make it
> work in netscape next ;)

> doug

for other browsers... you might try something like this

var photos =[];
for(i=0;i<document.images.length;i++){
if(document.images[i].name=="photo")
   photos[photos.length]=document.images[i];

Quote:
}



> Have you tried a reference via document.all["photo"] assuming only <img>
> elements have the name "photo"?

> --
> Michael Harris
> Microsoft.MVP.Scripting
> Seattle WA US



Tue, 31 Aug 2004 12:52:20 GMT  
 this should be an array

Quote:

> > that worked!  thanks a million!  i guess i'll need to see how to make it
> > work in netscape next ;)

> > doug

> for other browsers... you might try something like this

> var photos =[];
> for(i=0;i<document.images.length;i++){
> if(document.images[i].name=="photo")
>    photos[photos.length]=document.images[i];
> }

I realize that by "Netscape", Doug probably meant the Jurassic Browser (NS4),
but there is a DOM-1 method that non-IE browsers that support DOM-1 can use:

var photos = document.getElementsByName("photo");

--
The teacher is like the candle which lights others in consuming
itself. -Giovanni Ruffini

=-=-=
Steve
-=-=-



Tue, 31 Aug 2004 21:02:35 GMT  
 this should be an array

Quote:




>>>that worked!  thanks a million!  i guess i'll need to see how to make it
>>>work in netscape next ;)

>>>doug

>>for other browsers... you might try something like this

>>var photos =[];
>>for(i=0;i<document.images.length;i++){
>>if(document.images[i].name=="photo")
>>   photos[photos.length]=document.images[i];
>>}

> I realize that by "Netscape", Doug probably meant the Jurassic Browser (NS4),
> but there is a DOM-1 method that non-IE browsers that support DOM-1 can use:

> var photos = document.getElementsByName("photo");

I did think of that first... but you know... unfortunately that browser
is an "undead" monster clung to by a small percentage who never the less
account for a large number of people.

Lance



Thu, 02 Sep 2004 07:53:08 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. javascript array problem, or am I just stupid!!!

2. wsh/ jscript : BUG : array of array, 2D array

3. Server Array to Client-Side Array

4. Compose JavaScript Array by VB array

5. perl hash array/javascript arrays

6. Help converting server-side VBScript array into client-side JScript array

7. Array size of a 2 dimensional array

8. VB array to Java Array

9. Array of arrays with ASP

10. Passing Array to Session Variable Then back to Array

11. Server Array to Client-Side Array

12. array pointing to other arrays

 

 
Powered by phpBB® Forum Software