Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 24th, 2004, 02:33 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default 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 ?
__________________
`~@#\^%&*/\.<.\/-|+|_!:;..=?>
PHP, SEO | anshul shrivastava | mediasworks.org | FB
Reply With Quote
  #2 (permalink)  
Old July 24th, 2004, 03:27 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You aren't passing any values in the setTimeout calls:

setTimeout("animate2()",99);

should be:

setTimeout("animate2(img)",99);

HTH,

Snib

<><
Reply With Quote
  #3 (permalink)  
Old July 25th, 2004, 04:34 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

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.
Reply With Quote
  #4 (permalink)  
Old July 26th, 2004, 02:30 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

if some of u've this problem as i'd, u can solve it simply using javascript in-built eval() function.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Variables silve1999 Pro Java 1 June 15th, 2006 12:54 PM
Passing variables karlirvin Beginning PHP 3 December 9th, 2005 04:37 PM
Passing variables karlirvin PHP How-To 4 December 2nd, 2005 08:02 PM
Passing variables jesseleon Access VBA 4 October 24th, 2003 01:45 PM



All times are GMT -4. The time now is 12:10 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.