-3

Although I know a lot about these languages now such as arrays and functions, I'm having a basic problem to getting this JavaScript to run, here's the code:


<!DOCTYPE html>
<html>

<head>
</head>

<body>
  <input type="submit" value="submit" onclick="click()" />
  <script>
    function click() {
      alert("hey");
    }
  </script>
</body>

</html>
Andrew Li
  • 55,805
  • 14
  • 125
  • 143
Isaiah. H
  • 7
  • 3
  • 5
    Rename your `click()` function. You happened to choose an unfortunate name. –  Sep 22 '16 at 14:28
  • `click` is a JavaScript function, and redeclaring it is causing problems. Rename it – Andrew Li Sep 22 '16 at 14:31
  • Possible duplicate of [javascript function name cannot set as click?](http://stackoverflow.com/questions/4388443/javascript-function-name-cannot-set-as-click) – Frank Tan Sep 22 '16 at 14:45

2 Answers2

1

You're running into this problem: javascript function name cannot set as click?

You can fix this by changing the function name to something else like function myClick

<head>
</head>

<body>
  <input type="submit" value="submit" onclick="myClick()" />
  <script>
    function myClick() {
      alert("hey");
    }
  </script>
</body>

</html>
Community
  • 1
  • 1
Joseph Evans
  • 1,360
  • 9
  • 14
0

yes,like the comment above. you should use a different name instead of click()

 function submit() {
      alert("hey"); }
<html>

<head>
</head>

<body>
  <input type="submit" value="submit" onclick="submit()" />
 </body>

</html>
manu padmanabhan
  • 59
  • 1
  • 1
  • 8