Select to view content in your preferred language

calling functions from html script, using AMD syntax

7558
11
Jump to solution
09-04-2013 12:00 PM
DavidMarquardt
Deactivated User
Hi,

I???m having problems adjusting my functions to the AMD syntax.

I have some html checkboxes that call a update visibility function.  I have some scripting in the html code that passes on unique arguments to the function.  In the legacy script, this worked fine.  When I transferred over to the AMD syntax (putting all functions inside the AMD require statement), the update visibility function is not recognized by the html code. But, if I take the function out of the require statement, the html scripting recognizes it.  In this situation, though, the update visibility function can't recognize any of the modules or elements left in the require statement.   How do I call a function from an html script that's inside the require statement?

Here???s the stripped down format I have that doesn???t work

<script src="http://js.arcgis.com/3.6/" type="text/javascript"></script>
<script  type="text/javascript">

require([ a bunch of modules ], function ( modules) {
  ready (function() {
    map = ???..           
    function updateLayerVisibility (arg1, arg2) { ???..}                                               
});
});

</script>
<body>
  <input type='checkbox' class='list_item' id='foodLyr3' value=3 onclick='updateLayerVisibility(arg1, arg2);'  /></input>
</body>
0 Kudos
11 Replies
JeffJacobson
Frequent Contributor
You should be able to just have one function handle all of the checkboxes if they are all basically doing the same thing but affecting a different layer.

Inside of your event handler function, the this keyword will be pointing to the checkbox that was clicked. You can use that to access the attributes of the checkbox (HTML input element). You can have a data-layer-id attribute, for example.
0 Kudos
DavidMarquardt
Deactivated User
Thank you all for your help.

I redesigned my code based on your advice. 

Good to know there is a way to make a function accessible, if necessary.

David
0 Kudos