Hello-
I have a javascript problem which seems that it ought to be soluble without eval, but I can only make it work with eval.
With the script below the call:
"ImageChange('m yImageName', newImage);" works fine, but:
"channelChange( 'myImageName'); " does not. The string anewsrc is being treated as a string, and not as an object even though I am asking for it's "src" property.
--------------------
function ImageChange(ima gename, newsrc)
{
document.images[imagename].src=newsrc["src"];
}
function channelChange(n ewchan) {
var anewsrc;
for (var i = 0; i < document.images .length; i++) {
if (document.image s[i].stackname) {
anewsrc=(docume nt.images[i].stackname + "_" + newchan);
ImageChange(doc ument.images[i].stackname, anewsrc);
}
}
}
-------------------------
However switching to :
--------------------
function ImageChange(ima gename, newsrc)
{
document.images[imagename].src=newsrc["src"];
}
function channelChange(n ewchan) {
var anewsrc;
for (var i = 0; i < document.images .length; i++) {
if (document.image s[i].stackname) {
anewsrc=(docume nt.images[i].stackname + "_" + newchan);
ImageChange(doc ument.images[i].stackname, eval(anewsrc)); //<-!-
}
}
}
-------------------------
allows it to work with both calls.
Is there a better alternative here?
Thanks,
Leo
I have a javascript problem which seems that it ought to be soluble without eval, but I can only make it work with eval.
With the script below the call:
"ImageChange('m yImageName', newImage);" works fine, but:
"channelChange( 'myImageName'); " does not. The string anewsrc is being treated as a string, and not as an object even though I am asking for it's "src" property.
--------------------
function ImageChange(ima gename, newsrc)
{
document.images[imagename].src=newsrc["src"];
}
function channelChange(n ewchan) {
var anewsrc;
for (var i = 0; i < document.images .length; i++) {
if (document.image s[i].stackname) {
anewsrc=(docume nt.images[i].stackname + "_" + newchan);
ImageChange(doc ument.images[i].stackname, anewsrc);
}
}
}
-------------------------
However switching to :
--------------------
function ImageChange(ima gename, newsrc)
{
document.images[imagename].src=newsrc["src"];
}
function channelChange(n ewchan) {
var anewsrc;
for (var i = 0; i < document.images .length; i++) {
if (document.image s[i].stackname) {
anewsrc=(docume nt.images[i].stackname + "_" + newchan);
ImageChange(doc ument.images[i].stackname, eval(anewsrc)); //<-!-
}
}
}
-------------------------
allows it to work with both calls.
Is there a better alternative here?
Thanks,
Leo
Comment