JavaScript Alert problem in imagemap

JavaScript Alert problem in imagemap

Post by dgmoor » Wed, 04 May 2005 23:57:26

Hello -

I'm having trouble with JavaScript alerts in an imagemap. The mapped
areas are cells in a table, and the alerts display info related to the
cell that is clicked. The problem is that, even though the source html
is correct, the alert messages that are displayed appear to be random,
i.e., the alert for row 10 appears when row 3 is clicked, etc. On some
long tables, the same alert message is displayed for (nearly) every row
even though the html contains the correct message for each row.

It looks like, among other things, perhaps the alert is not being
"cleared" consistently after after being invoked, and when the next row
is clicked the info from the preceding choice is displayed again.

I'm using
*******************************************************
<script language="JavaScript" type="text/javascript">
<!--
var alert_msg = "";
alert_msg +="Line 1";
alert_msg +="\nLine 2";
alert_msg +="\nLine 3";
// -->
</script>

<area SHAPE+"RECT" COORDS="0,62,287,92" HREF = "#"
OnClick="alert(alert_msg);return false;"></a>
*********************************************************
Can anybody point out the error of my ways?

Thanks
Dave

 
 
 

JavaScript Alert problem in imagemap

Post by dgmoor » Thu, 05 May 2005 00:15:09

As Rosanne RosannaDanna used to say, "...Never mind". I failed to index
the successive alert_msg's in the script, so each one was overwriting
the preceding one and they all wound up being the same. I changed var
alert_msg to var alert_msg & N, where N is incremented each time.
Problem solved.

Thanks anyway...
Dave

 
 
 

JavaScript Alert problem in imagemap

Post by Lee » Thu, 05 May 2005 00:45:00


XXXX@XXXXX.COM said:

You haven't shown us anything that would make the alert message
different for different areas. Do different areas display different
variables?
 
 
 

JavaScript Alert problem in imagemap

Post by dgmoor » Thu, 05 May 2005 01:49:24

Yes - the data to be displayed for each area is different, but since I
hadn't subscripted the alert message variable, when the page loaded it
was being processed from beginning to end so all of the messages
displayed the text of the last message processed. I changed it so each
successive message variable is different (msg1, msg2, msg3, etc.) and
this fixed the glitch.

Thanks
Dave