how to call module function on button click event in html page
Here's how I do it (for a link, but same concept for button):
Main map module (which calls another module - mapPrint)
window.mapPrintExec = function () { var objMapPrint = new mapPrint({ "contentHTML": document.documentElement.innerHTML, "pageHeight": $('.tundra').height(), "pageWidth": $('.tundra').width(), "trgNodeRef": dom.byId("mapPrintLink"), "mapDescription": strMapDesc, "mapSource": strMapSource }); objMapPrint.print(); }
HTML
<a href="#" class="emptyLink" id="mapPrintLink" onclick="mapPrintExec();"><img src="../ContentHandlers/Images/Images.ashx?printer.png" /> Print</a>
As an alternative to using the onclick event in the HTML node you can hook up the event using Javascript:
<SPAN class="com" style="color: #808080;">// Use a function pointer:</SPAN><SPAN class="pln" style="color: #000000;"> document</SPAN><SPAN class="pun" style="color: #000000;">.</SPAN><SPAN class="pln" style="color: #000000;">getElementById</SPAN><SPAN class="pun" style="color: #000000;">(</SPAN><SPAN class="str" style="color: #800000;">"myButtonId"</SPAN><SPAN class="pun" style="color: #000000;">).</SPAN><SPAN class="pln" style="color: #000000;">onclick </SPAN><SPAN class="pun" style="color: #000000;">=</SPAN><SPAN class="pln" style="color: #000000;"> doSomething</SPAN><SPAN class="pun" style="color: #000000;">;</SPAN>
Just in case he's looking for a dojo-specific example!
registry.byId("myButtonId").connect("onClick", function myFunc(){ doSomething; });
I find myself mixing dojo, jQuery, and pure JS sometimes...
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.