|
|
 |
| Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

July 24th, 2004, 03:33 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 ?
|

July 24th, 2004, 04:27 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You aren't passing any values in the setTimeout calls:
setTimeout("animate2()",99);
should be:
setTimeout("animate2(img)",99);
HTH,
Snib
<><
|

July 25th, 2004, 05:34 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
no that is not working.
actually i think i m not able2(transmit/transit) DOM variables containing values from one function2another in that functions.
.. but why document.writeln(img); outputs as if values are passed ..
also if i put constant values like 'image1', 'image2'
in this code without any suggested modification like
{setTimeout("animate2('image1')",99);}, these functions works. DOM values are not getting into functions correctly ?
can anyone list few urls that explain exhaustive/comprehensive information about javascript functions. i couldn't find this at sites like javascriptkit.com, dynamicdrive.com etc.
|

July 26th, 2004, 03:30 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
if some of u've this problem as i'd, u can solve it simply using javascript in-built eval() function.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |