[thelist] javascript: can't call function in function?
AtdtXav
atdtxav at yahoo.com
Fri Mar 1 15:04:00 CST 2002
Here's the deal. I'm making a page more dynamic than it was
before, sort of economizing on code and such. I intend to use
just one page by the time I'm finished.
I use WM_imageSwap (you may recall it from monkeyjunkies,
oldtimers) for my image swapping, which I call before the body
at the top of the page.
This functions fine as it is being called normally.
However, when I build the page using a new javascript file I
call buildnav, I don't get any mouseover functionality. I'm
thinking this is related to some function-in-a-function error,
but I'm just not familiar enough to know for sure.
Help? :)
the vital parts of the javascript are replicated below:
First, WM_imageswap:
function WM_imageSwap(daImage, daSrc){
var objStr,obj;
/*
WM_imageSwap()
Changes the source of an image.
Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)
Author: Shvatz
Author Email: shvatz at wired.com
Usage: WM_imageSwap(originalImage, 'newSourceUrl');
Requires: WM_preloadImages() (optional, but recommended)
Thanks to Ken Sundermeyer (ksundermeyer at macromedia.com) for
his help
with variables in ie3 for the mac.
*/
// Check to make sure that images are supported in the DOM.
if(document.images){
// Check to see whether you are using a name, number, or
object
if (typeof(daImage) == 'string') {
// This whole objStr nonesense is here solely to gain
compatability
// with ie3 for the mac.
objStr = 'document.' + daImage;
obj = eval(objStr);
obj.src = daSrc;
} else if ((typeof(daImage) == 'object') && daImage &&
daImage.src) {
daImage.src = daSrc;
}
}
}
Next, my own function:
// The Tomorrow Men
var alttag = "The Tomorrow Men";
var named = "tomorrow";
displaynav(alttag, named);
// (repeat for rest of nav)
function displaynav(alttag, named)
{
if (location.search.substring(1) == named)
var here = "loc";
else
var here = "off";
// document.write('<IMG src="images/' + named + '_' + here +
'.gif"><BR>');
document.write("XA href="index.html?" + named + ""
onMouseOver="");
document.write("WM_imageSwap('" + named );
document.write("', 'images/" + named + "_on.gif');"
onMouseOut="");
document.write("WM_imageSwap('" + named + "', 'images/" + named
+ "_" + here + ".gif');">");
document.write("Ximg name="" + named + """);
document.write(' src="images/' + named + '_' + here + '.gif"
border=0 width="130" alt="');
document.write(alttag + '"></A><BR>');
}
here is a working HTML page:
http://spork.ofdoom.com/skd/
and here is the (in progress) javascript version:
http://spork.ofdoom.com/atdt/
__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - Send FREE e-cards for every occasion!
http://greetings.yahoo.com
More information about the thelist
mailing list