Image map doesn't work with javascript function
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:
Code:
<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>
Re: Image map doesn't work with javascript function
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.
Re: Image map doesn't work with javascript function
Can't believe I missed that, but thank you.
Quote:
Originally Posted by CornedBee
By my standards, the code is horribly broken, but that's a different issue.
I'm a beginner to this, could you explain?
Re: Image map doesn't work with javascript function
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.
Re: Image map doesn't work with javascript function
Looks like I need a new book!