Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2004, 02:33 PM
Friend of Wrox
 
Join Date: Mar 2004
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
 
Old July 24th, 2004, 03:27 PM
Friend of Wrox
 
Join Date: Nov 2003
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

<><
 
Old July 25th, 2004, 04:34 PM
Friend of Wrox
 
Join Date: Mar 2004
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.
 
Old July 26th, 2004, 02:30 PM
Friend of Wrox
 
Join Date: Mar 2004
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.





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





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