PDA

Click to See Complete Forum and Search --> : Image map doesn't work with javascript function


System_Error
Jul 10th, 2005, 12:23 PM
I've created a simple function that should update a textfield based on an image map. For some reason this is not working and I can't find any problems with the code. If you can help out, please do.

The code is as follows:


<html>
<head>
<title>Mapping Example</title>
<script language="JavaScript" type="text/javascript">

function update(t)
{
document.form1.text1.value = t;
}

</script>
</head>
<body>
<map name="map1>
<area shape="rect" coords="0,0,100,100" onClick="update('left');">
<area shape="rect" coords="20,0,40,40" onClick="update('right');">
</map>
<h1>Image map example</h1>
<hr>
<img src="mateintwo.jpg" usemap="#map1">
</hr>

<form name="form1">
<input type="text" name="text1">
</form>
</body>
</html>

CornedBee
Jul 10th, 2005, 07:02 PM
By my standards, the code is horribly broken, but that's a different issue.

If I just put the missing quote at the end of the name attribute of the map tag, the code works for me in Firefox.

System_Error
Jul 10th, 2005, 11:27 PM
Can't believe I missed that, but thank you.

By my standards, the code is horribly broken, but that's a different issue.


I'm a beginner to this, could you explain?

CornedBee
Jul 11th, 2005, 04:47 AM
1) You use the HTML pseudo-DOM for accessing elements.
2) You use name instead of id.
3) You miscapitalize onclick.
4) You have insufficient separation of structure and behaviour. (But that can be excused since this is just an example.)

That aside, an image map is, by basic principle, completely inaccessible to any non-graphical browsers.

System_Error
Jul 11th, 2005, 11:32 AM
Looks like I need a new book!