Select to view content in your preferred language

Button

1613
11
Jump to solution
03-25-2014 04:28 AM
jaykapalczynski
Honored Contributor
Looking to create a simple button that runs some code like IDENTIFY. 
I am looking for two scenarios:
1.  The button must be pressed each time you want to run the code
2.  The code runs until you select another button

Anyone of an example for each...Appreciated.
0 Kudos
11 Replies
PaulVepraskas
Frequent Contributor
Here is the FULL working code...  click the button on the lower left of the map, then click the map. alert will pop up.  click the map again.  No alert. 

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9">
    
    <title>mapMUSKEGO | mapVEPRASKAS</title>
 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <link rel="stylesheet" href="http://js.arcgis.com/3.6/js/dojo/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="http://js.arcgis.com/3.6/js/esri/css/esri.css">

<style type="text/css">

      html,body,#map{
        padding:0;
        margin:0;
        overflow:hidden;
        height:100%;
        background-color:#dbddda;
      }
      
      
 </style>

 <script src="http://js.arcgis.com/3.8/"></script>

    <script>
   dojo.require("esri.map");
  
   var map;
   var initExtent;
   
   var buttonclick;
   
   function init() {
    initExtent = new esri.geometry.Extent(2485078.859947771, 312461.2599477768, 2517629.6100261062, 344895.2419843375, new esri.SpatialReference({ "wkid": 32054 }));

             map = new esri.Map("map", { extent: initExtent, logo: false, slider: false});

             var greyMAP = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer", { });
             map.addLayer(greyMAP);
   } 
   
   function buttoncall() {
       buttonclick = dojo.connect(map, "onClick", resultFunction);
   }
   
   function resultFunction() {
       dojo.disconnect(buttonclick);
       alert("test");
   }  
   
   dojo.ready(init);
   
   
  </script>

 </head>

 <body>  
  <div id="map"></div>
  <a href="javascript:buttoncall()" id="button1" ><img alt="button1IMG" id="button1IMG" style="bottom:10px; left: 10px; width:36px; position:absolute; z-index:22;  border:none;" src="images/Button.png"/></a>
</body>
</html>
0 Kudos
jaykapalczynski
Honored Contributor
Fantastic...works great...thanks....very appreciated.
0 Kudos