Re: [Javascript] dynamic variables names
grillo at lazzuri.com.br
grillo at lazzuri.com.br
Thu Jun 26 02:45:45 CDT 2003
Text1
-------------- next part --------------
Ok, I understood now what you'd say.
Sorry, but my knowledge of javascript is based in actionscript, it's the same reference language but not the same, I know.
I have tried using alert(document.images); and it did trace to [object] which is correct, but when I try to do alert(document.images[nt_01]) or alert(document.images[nt_01].src) all I get is an undefined and I don't know why.
this is the code for my image
<td><a href="#"><img src="../_img/1_nota_01_off.gif" name="nt_01" width="16" height="26" border="0" onMouseOver="note(1);" onMouseOut="out()"></a></td>
( i had typed wrong in the first email saying nt_o1, but it was only in the email )
thanks for explaining me
Marcelo Simon
----- Original Message -----
From: Chris Tifer
To: [JavaScript List]
Sent: Tuesday, June 24, 2003 3:25 PM
Subject: Re: [Javascript] dynamic variables names
I fully understood what you're doing. I didn't need to see
the rest. You're trying to dynamically set an image's source.
I'm sure you have them named:
nt_o1, nt_o2, nt_o3, etc...
What I was saying is that you're referencing them incorrectly
which is why you think you need a dynamic variable. If you were
to reference the element through the .image collection, you'd
be able to access them by name or index.
Since you're looking to reference them by name (the correct
choice in my book), you are forming a value, not a variable.
Your value is the string "nt_o" + the dynamic value of i
So my real suggestion out of that was to reference the image
through the collection rather than trying to reference it by
ID.
Chris Tifer
http://emailajoke.com
----- Original Message -----
From: Marcelo Simon
To: [JavaScript List]
Sent: Tuesday, June 24, 2003 1:44 PM
Subject: Re: [Javascript] dynamic variables names
Thanks for the answers, but they didn't solve my problem.
I didn't post the entire function, and that's why I think you say that I don't have a dynamic variable name. ( or maybe I'm wrong ), here's the function
function note(number){
for ( var i=1; i < 6; i++){
if ( i <= number ){
alert(['nt_0'+i].src); // it's tracing undefined
['nt_o'+i].src = '../_img/1_note_0'+i+'_on.gif';
} else {
['nt_o'+i].src = '../_img/1_note_0'+i+'_off.gif';
}
}
}
what I'm trying to accomplish, is to change some images from 1 to i based on the number I pass to the function (ie. if I pass 3, I want images 1,2 and 3 to be on and 4 and 5 to be off ), so if someone has a different approach to this please share.
Thanks again
Marcelo Simon
----- Original Message -----
From: Chris Tifer
To: [JavaScript List]
Sent: Tuesday, June 24, 2003 1:10 PM
Subject: Re: [Javascript] dynamic variables names
Do you have a dynamic variable name? I would never use a
dynamic variable to be honest with you - or at least haven't ever
found the need for one yet, but from the looks of it below, you
don't have a dynamic variable, but rather you're trying to build
a reference to an image dynamically.
To do that, use the document.images collection and
build your string when targeting a specific element in that
collection:
document.images["nt_o" + i].src = "path/to/image.gif"
That's not a dynamic variable name - just so you're aware.
Chris Tifer
http://emailajoke.com
----- Original Message -----
From: Marcelo Simon
To: * Yahoo / Javascript
Sent: Tuesday, June 24, 2003 11:50 AM
Subject: [Javascript] dynamic variables names
Hi list,
It's me again, and I need some help again please.
how can I use dynamic variables name in JS ?
I mean, how do I evaluate the 2 parts so they work ?
if ( i <= number ){
['nt_o'+i].src = '../_img/1_nota_0'+i+'_on.gif';
}
thanks in advance
------------------------------------------------------------------------
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
--------------------------------------------------------------------------
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
----------------------------------------------------------------------------
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
------------------------------------------------------------------------------
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030626/d98ae400/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Mime.822
Type: application/octet-stream
Size: 21376 bytes
Desc: not available
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030626/d98ae400/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Part.002
Type: application/octet-stream
Size: 151 bytes
Desc: not available
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030626/d98ae400/attachment-0001.obj>
-------------- next part --------------
AdmID:548683DF1B864709933C5D523DE59C16
More information about the Javascript
mailing list