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

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"

thanks
willsherwoodAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
hieloConnect With a Mentor Commented:
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:
http://www.yoursite.com/process.php?planet=mercury

Look at the complete example below. I am sending the selections directly to Google.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
 "http://www.w3.org/TR/REC-html40/loose.dtd">
 
<html>
<head><base href="http://www.w3schools.com/tags/tag_map.asp"/>
<title></title>
</head>
<body>
<p>Click on one of the planets:</p>
 
<img src ="planets.gif"
width ="145" height ="126"
alt="Planets"
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" />
</map>
</body>
</html>

Open in new window

0
 
LordOfPortsConnect With a Mentor Commented:
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" >
<head>
    <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);
        
        document.getElementById('frmImage').submit();
    }
    // ]]>
    </script>
</head>
<body>
 
<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');" />
</map>
 
<input type="hidden" id="hidVal" name="hidVal" />
 
</form>
 
</body>
</html>

Open in new window

pic.png
0
 
willsherwoodAuthor Commented:
quick and right on target - thanks to BOTH!!
0
All Courses

From novice to tech pro — start learning today.