<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Add functionality to &amp;lt;button&amp;gt; tag embedded in an InfoWindow in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352169#M32640</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This could get tricky as the button and event listener would get generated each time the content is created, leading to memory leaks in your application.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A simple approach may be to add the button as normal, but give it a class name of say "btn-action" or similar.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you can use dojo/on to do this somewhere in your app:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;on(document.body, ".btn-action:click", function(e) {
&amp;nbsp; // do something on button click
});&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can look at the &lt;A href="https://dojotoolkit.org/documentation/tutorials/1.10/events/" rel="nofollow noopener noreferrer" target="_blank"&gt;Event Delegation section of the docs for details&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 16:32:38 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2021-12-11T16:32:38Z</dc:date>
    <item>
      <title>Add functionality to &lt;button&gt; tag embedded in an InfoWindow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352163#M32634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hola everybody,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've successfully added an html button within an InfoWindow.&amp;nbsp; However, I am having trouble calling functionality when the button is clicked.&amp;nbsp; I've tried onClick within the html tag, using the 'on' event listener, and querying for the button class and listening for the 'click' event.&amp;nbsp; If someone could point me in the right direction that would be great.&amp;nbsp; Thanks for your time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cz&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var sources = search.sources;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sources.push({&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; featureLayer: layer,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; placeholder: "L0400409",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; enableLabel: false,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; searchFields: ["NUMBER_KEY"],&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; displayField: "NUMBER_KEY",&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; exactMatch: false,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFields: ["*"],&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Create an InfoTemplate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infoTemplate: new InfoTemplate("Casefile Info", "&amp;lt;a href= ${CASE_NUM} target=_blank ;'&amp;gt;Additional Info&amp;lt;/a&amp;gt;&amp;lt;/br&amp;gt;&amp;lt;/br&amp;gt;NumberKey: ${NUMBER_KEY}&amp;lt;/br&amp;gt;TLNO: ${TLNO}&amp;lt;/br&amp;gt;&amp;lt;button type='button' id='infoBtn' class='infoBtn';'&amp;gt;Click Me&amp;lt;/button&amp;gt;")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Add functionality to the infoBtn here&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Sep 2015 21:50:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352163#M32634</guid>
      <dc:creator>JonathanCzerniak</dc:creator>
      <dc:date>2015-09-24T21:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Add functionality to &lt;button&gt; tag embedded in an InfoWindow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352164#M32635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;button type='button' id='infoBtn' class='infoButn' onclick="myFunction()'&amp;gt;Click Me&amp;lt;/button&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with the function in a &amp;lt;script&amp;gt; tag in &amp;lt;head&amp;gt; area of the page.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;script language="javascript"&amp;gt;&lt;/P&gt;&lt;P&gt;function myFunction()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'do stuff&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;lt;/script&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Sep 2015 22:25:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352164#M32635</guid>
      <dc:creator>RichardDaniels</dc:creator>
      <dc:date>2015-09-24T22:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: Add functionality to &lt;button&gt; tag embedded in an InfoWindow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352165#M32636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Richard,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried this approach as the call to the infoTemplate is already nested within a &amp;lt;script&amp;gt; tag which is in the &amp;lt;head&amp;gt; tag.&amp;nbsp; I realized that I should have included the whole code so I attached the entire code to the original message for reference.&amp;nbsp; Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Sep 2015 22:47:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352165#M32636</guid>
      <dc:creator>JonathanCzerniak</dc:creator>
      <dc:date>2015-09-24T22:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Add functionality to &lt;button&gt; tag embedded in an InfoWindow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352166#M32637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you using IE? IE sometimes does not like the button element. And, depending on the rest of your application (ie: if it's .NET), the button element is going to do a full postback. I would try again but use the input type=button element just for giggles. It might not be the solution, but it's worth a try. I avoid the button element b/c of inconsistencies.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2015 15:05:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352166#M32637</guid>
      <dc:creator>TyroneBiggums</dc:creator>
      <dc:date>2015-09-25T15:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Add functionality to &lt;button&gt; tag embedded in an InfoWindow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352167#M32638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another approach would be to use a function instead of a template string. (See Using Custom Functions section &lt;A href="https://developers.arcgis.com/javascript/jshelp/intro_formatinfowindow.html"&gt;here&lt;/A&gt;.) Inside of the function, use &lt;A href="https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement"&gt;document.createElement&lt;/A&gt; and &lt;A href="https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild"&gt;element.appendChild&lt;/A&gt; to construct your DOM elements. After you've used created your Button element, use &lt;A href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener"&gt;addEventListener&lt;/A&gt; to set the button's "click" event.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Sep 2015 17:24:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352167#M32638</guid>
      <dc:creator>JeffJacobson</dc:creator>
      <dc:date>2015-09-28T17:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Add functionality to &lt;button&gt; tag embedded in an InfoWindow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352168#M32639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jeff,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You wouldn't happen to have an example of how to use the document.createElement and element.appendChild would you?&amp;nbsp; I've tried a couple things and this is as far as I can get.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/128936_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;Here is the code that produces this result.&amp;nbsp; I left out the element.appendChild because I'm not sure to which element I append the object.&amp;nbsp; Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cz&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; function getTextContent(graphic){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var names = graphic.attributes.x_coord;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var y_coord = graphic.attributes.y_coord&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var commName = names;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var btn = document.createElement("BUTTON");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; btn.innerHTML = 'click me';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(commName === ""){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; commName = names[0];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "&amp;lt;b&amp;gt;" + commName + "&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;p &amp;gt;" + y_coord&amp;nbsp; +"&amp;lt;/p&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;button&amp;gt;" + btn +"&amp;lt;/button&amp;gt;";&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Sep 2015 21:09:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352168#M32639</guid>
      <dc:creator>JonathanCzerniak</dc:creator>
      <dc:date>2015-09-29T21:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Add functionality to &lt;button&gt; tag embedded in an InfoWindow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352169#M32640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This could get tricky as the button and event listener would get generated each time the content is created, leading to memory leaks in your application.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A simple approach may be to add the button as normal, but give it a class name of say "btn-action" or similar.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you can use dojo/on to do this somewhere in your app:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;on(document.body, ".btn-action:click", function(e) {
&amp;nbsp; // do something on button click
});&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can look at the &lt;A href="https://dojotoolkit.org/documentation/tutorials/1.10/events/" rel="nofollow noopener noreferrer" target="_blank"&gt;Event Delegation section of the docs for details&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:32:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352169#M32640</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-12-11T16:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: Add functionality to &lt;button&gt; tag embedded in an InfoWindow</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352170#M32641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That worked great!&amp;nbsp; Thank you, Rene!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Sep 2015 16:12:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-functionality-to-lt-button-gt-tag-embedded-in/m-p/352170#M32641</guid>
      <dc:creator>JonathanCzerniak</dc:creator>
      <dc:date>2015-09-30T16:12:06Z</dc:date>
    </item>
  </channel>
</rss>

