[Javascript] dynamic variables names
Marcelo Simon
grillo at lazzuri.com.br
Tue Jun 24 12:44:25 CDT 2003
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030624/4f4beb4c/attachment.htm>
More information about the Javascript
mailing list