Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a parameter passed in through a function for use in an array

Status
Not open for further replies.

finty

Programmer
Jun 7, 2002
10
GB
why won't this work?

This code doesn't do anything useful as it appears but it does demonstrate my problem. The problem seems to be with my syntax.
The problem I have is giving the value of the parameter that is passed in through the function fade_in() and
using it to identify the correct image within an array. It tells me that it is null or not an object.


It appears to be very simple but I can't figure it out.

------------
in the head tag:

var overButtons = new Array();

overButtons["development"] = new Image(146,18)
overButtons["development"].src= "../images/development.gif";

function fade_in(imageURL)
{
...............code........

var tempURL = overButtons["development"].src;//this works naturally
var tempURL2 = overButtons[imageURL].src; //there is a problem with this line for some reason

.........code..............

}

-------------
in the body

<a href=&quot;#&quot; onMouseOver=fade_in('development');&quot;><img name=&quot;development&quot; src=&quot;../images/development.gif&quot;></a>
 
You just cannot access an item of images array that way.
You can do it using 2 ways only: using 'name' attribute of the <img> tag (like you did for tempURL) or using item's number in images array (like document.images[n]).
 
hi finty,

using eval() should work...change this:
[tt]var tempURL2 = overButtons[imageURL].src;[/tt]

to this:
[tt]var tempURL2 = eval(&quot;overButtons['&quot; + imageURL + &quot;'].src;&quot;); [/tt] =========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top