Results 1 to 5 of 5

Thread: Image map doesn't work with javascript function

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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>

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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?

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Image map doesn't work with javascript function

    Looks like I need a new book!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width