...

View Full Version : Image button problem



jdruwe
12-22-2011, 05:38 PM
Hey i have a map (belgium) with markers on it, when i press a marker an alert has to appear with some text but it just doesnt appear

I dont want to use javascript in my html

this is what i got atm,

html:


<div class="mapdiv">
<img class="map" src="images/Map.gif"/>
<img type="image" id="markerJoly" src="images/dot.png"/>
<img type="image" id="markerDielis" src="images/dot.png"/>
<img type="image" id="markerRietje" src="images/dot.png"/>
<img type="image" id="markerClissen" src="images/dot.png"/>
</div>

javascript:


addEventListener("load", Map, false);


function Map(event) {


var knop1 = document.getElementById("markerJoly");
if (knop1.onclick){
AlertBox1();
}

function AlertBox1() {
alert("1.")
}

function AlertBox2() {
alert("2.")
}

function AlertBox3() {
alert("3")
}

function AlertBox4() {
alert("4")
}

}


Alert doesnt show up, pls help

Thanks in advance

Logic Ali
12-22-2011, 06:04 PM
if (knop1.onclick)I don't know what you think that does, but it simply tests that knop1 has a property called onclick whose value evaluates true.


if( event.target == knop1 ) /* Won't work < IE9 */
{
AlertBox1();
}

xelawho
12-22-2011, 06:09 PM
I thought he was looking for


knop1.onclick=AlertBox1;

jdruwe
12-22-2011, 06:15 PM
I thought he was looking for


knop1.onclick=AlertBox1;

i want that pressing a marker activate that alert

xelawho
12-22-2011, 06:24 PM
does that not happen with the code I posted?

jdruwe
12-22-2011, 06:49 PM
Yea sorry typo ^^

Logic Ali
12-22-2011, 08:01 PM
i want that pressing a marker activate that alert


<div class="mapdiv" id="mapDiv">
<img class="map" src="images/Map.gif"/>
<img type="image" id="markerJoly" src="images/dot.png"/>
<img type="image" id="markerDielis" src="images/dot.png"/>
<img type="image" id="markerRietje" src="images/dot.png"/>
<img type="image" id="markerClissen" src="images/dot.png"/>
</div>

<script type="text/javascript">

function installListener( obj, evt, func )
{
window.attachEvent ? obj.attachEvent(evt,func) : obj.addEventListener( evt.replace( /^on/i, "" ), func, false);

return func;
}

installListener( document.getElementById( 'mapDiv' ), 'onclick', clickHandler );

function clickHandler( evt )
{
var elem = evt.target || evt.srcElement,
markers = elem.parentNode.getElementsByTagName( 'img' );

for( var i = 0; markers[ i ]; i++ )
if( markers[ i ] === elem )
alert( i + 1 );
}

</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum