We help IT Professionals succeed at work.

HTML/javascript/WebForm:   MapArea hotspot to set <input  value= >

willsherwood asked
Medium Priority
Last Modified: 2011-10-19
I have an application where i need to have the result of clicking on a hotspot (area map) within an image,  to do a submit immediately with a unique parameter that identifies which hotspot was clicked on.

Ex:   Image:
|       1     |       2      |
|       3     |       4      |

thus if the picture area around "1" above was clicked on,  a submit would be done with either the submit parameter or an input parameter set to "1"

Watch Question

Expert of the Year 2008
Top Expert 2008
The "hotspot" is typically associated to a url. On the url itself, you need to append the data you want to send. Example: if the <input> was:
<input name="planet" value="" type="hidden"> and it typically gets sent to http://www.yoursite.com/process.php, then you now need to update the url so that it contains all the information on the link. That way, when the user clicks on the hotspot the browser will send the information directly. As an example your link would need to change to:

Look at the complete example below. I am sending the selections directly to Google.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
<head><base href="http://www.w3schools.com/tags/tag_map.asp"/>
<p>Click on one of the planets:</p>
<img src ="planets.gif"
width ="145" height ="126"
usemap ="#planetmap" />
<map id ="planetmap" name="planetmap">
<area shape ="rect" coords ="0,0,82,126"
  href ="http://www.google.com/search?hl=en&btnG=Google+Search&q=sun" target ="_blank"
  alt="Sun" />
<area shape ="circle" coords ="90,58,3"
  href ="http://www.google.com/search?hl=en&btnG=Google+Search&q=mercury" target ="_blank"
  alt="Mercury" />
<area shape ="circle" coords ="124,58,8"
  href ="http://www.google.com/search?hl=en&btnG=Google+Search&q=venus" target ="_blank"
  alt="Venus" />

Open in new window

Below is another example of a possible solution; in this case javascript is used to set the value of a hidden field and to submit the form:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <title>Untitled Page</title>
    <script type="text/javascript">
    // <![CDATA[
    function SetValue(nVal)
        document.getElementById('hidVal').value = nVal;
        alert("Set value of hidden input field to: " + nVal);
    // ]]>
<form name="frmImage" id="frmImage" action="areamap.htm">
<img src="pic.png" usemap="#links" border="0" />
<map name="links">
<area shape="rect" coords="0, 0, 50, 50" href="javascript:SetValue('1');" />
<area shape="rect" coords="50,0,100,50" href="javascript:SetValue('2');" />
<area shape="rect" coords="0,50,50, 100" href="javascript:SetValue('3');" />
<area shape="rect" coords="50, 50, 100, 100" href="javascript:SetValue('4');" />
<input type="hidden" id="hidVal" name="hidVal" />

Open in new window



quick and right on target - thanks to BOTH!!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.