passing values and variables
passing values and variables
i've error in this code:
Error:'document.images[...]' is not an object
var state=1;
function animate1(img) {
document.images[img].src=downImage[0].src;
if(state==1) setTimeout("animate2()",99);
}
function animate2(img) {
document.images[img].src=defaultImage[0].src;
if(state==1) setTimeout("animate1()",99);
}
i pass 'img' parameter when onMouseOver="rollImage('image1', 'over');
this attribute is attached to name="image1" of the document image.
function rollImage(img, type) {
switch(type) {
case "over":
state="1";
animate1(img);
animate2(img);
break;
case "out":
state="0";
document.images[img].src=defaultImage[0].src;
break;
case "down":
state="0";
document.images[img].src=downImage[0].src;
break;
}
problem is that combination of above3functions not working.
error in arguments passing problem ?
but if we use 'document.writeln(img);' in functions animate1()
and animate2() we get right value 'image1' on screen.
also if we use 'document.images['image1'].src' or
'document.images["image1"].src' in these both functions above,
this code works fine. also if i've spelled 'image1' as image in
'document.images[image1].src' there is the same error i've said
in beginning in this post.
but i've2pass image_name to animate1() and animate2() via
rollImage() because i've >1 images in my document:
name="image1", name="image2", ....., name="image9", .., etc.
could i solve this argument-variable passing problem ?
u c that i tranmit a variable ( that contains some value )
through functions.
and code shown below works just fine: [Sun rises in the east.]
function a(a) {
a+=" rises";
b(a);
}
function b(b) {
b+=" in the east";
document.writeln(b);
}
function c(c) { a(c); }
var text="Sun";
c(text);
so what wrong i did with document ( DOM ) variables ?
|