Call javascript on onclick checkbox

I do not understand what I'm doing wrong here. I just want my function to be called when I click the checkbox. Replacing a function call with alert() works, am I referring to my function incorrectly?

 <html> <head></head> <body> <script type="text/javascript"> function select(a){ document.getElementById("myDiv").innerHTML=""+a; } </script> <input type="checkbox" onclick="select(1)"> <div id="myDiv">hi</div> </body> </html> 

thanks

+4
source share
2 answers

Change the function name [ex. selectFun]. select seems to be a reserved keyword

+13
source

It puzzled me, as it looked good to me too. So I ran a regular test, in the end I tried to change the name of the function, and it worked fine.

+3
source

All Articles