Select to view content in your preferred language

Checkbox onclick can not control the function, why?

737
2
Jump to solution
01-07-2014 12:17 PM
LeiZhou
Deactivated User
I tried to create a check box to turn on/off a layer.  The checkbox is just html code, and I want to control it by using the method onclick, as the following:
<input type='checkbox' class='list_item' id='0' value=0                     onclick="updateLayerVisibility();"/>PM2.5


The updateLayerVisibility() is defined in <script> </script> as the following:
function updateLayerVisibility (....DynamicLayer.visible = true; ) {}


I did not finish the function yet, but the test run always indicated that function updateLayerVisibility () is not defined.  I am very confused, I put checkbox in <body> </body> block, and put the function updateLayerVisibility() in the part B, like require ([ ...], fucniton () { part B}), why the onclick() is not working?  Any suggestion would hlep!  Thank you very much!
0 Kudos
1 Solution

Accepted Solutions
JonathanUihlein
Esri Regular Contributor
It has to do with scope. Your function is not within the global scope, but within the DOJO scope.

Instead of having onclick on your html input, just use an on event inside your require block.


on(dom.byId("0"), "click", function(evt){ // do something });


( Also, I would change the id of your input to something other than '0' )

View solution in original post

0 Kudos
2 Replies
JonathanUihlein
Esri Regular Contributor
It has to do with scope. Your function is not within the global scope, but within the DOJO scope.

Instead of having onclick on your html input, just use an on event inside your require block.


on(dom.byId("0"), "click", function(evt){ // do something });


( Also, I would change the id of your input to something other than '0' )
0 Kudos
LeiZhou
Deactivated User
Thanks a lot!
0 Kudos