j_liu21@hotmail.com wrote:[color=blue]
> Actually it seems it does work if I remove the usemap feature.
>
> <a href="javascript
:void(0)" onClick="alert('hi');"><IMG src="foo.gif"
> border="0"></a>
>
> The problem is I need to use the imagemap to determine where they
> click, but because the imagemap is reused multiple times, I don't have
> the context of which image the user actually clicked.
>
> <a href="javascript
:void(0)" onClick="alert('hi');"><IMG src="foo1.gif"
> name="foo1" usemap="#someImageMap" border="0"></a>
>
> <a href="javascript
:void(0)" onClick="alert('hi');"><IMG src="foo2.gif"
> name="foo2" usemap="#someImageMap" border="0"></a>
>
> Is there any way to capture this context in the map itself where I can
> retrieve the name?
> <map name="someImageMap">
> <area shape="rect" coords="0,0,15,16" onClick="inputValue(1,this)"
> ALT="Section 1">
> <area shape="rect" coords="16,0,33,16" onClick="inputValue(2,this)"
> ALT="Section 2">
> </map>
>[/color]
Pass 'this' from your area elements, then from the inputValue function
call a 'getMap' function that climbs up the node tree looking for
the parent map element, something like:
HTML:
<map ...>
<area ... onClick="inputValue(1, this)" ... >
<area ... onClick="inputValue2, this)" ... >
...
</map>
Script:
function inputValue( num, el ){
var mapRef;
if ( el && (mapRef = getMap(el)) ) {
// do stuff with the map reference
// ...
} else {
// couldn't find the map element
}
}
function getMap( a ){
while ( a.parentNode && 'map' != a.nodeName.toLowerCase() ){
a = a.parentNode;
}
return ( 'map' == a.nodeName.toLowerCase() )? a : false;
}
--
Rob