I just started learning JavaScript and am wondering why this simple snippet hangs when I click on the ‘Call function’ button. What am I missing?
<html> <head> <script type='text/javascript'> function myfunction() { document.write('hello'); } </script> </head> <body> <form> <input type='button' onclick='myfunction()' value='Call function'> </form> </body> </html>
You need to write inside an element or give an element a value, or you should use document write like that :