Two observations:
-
You should write
<input type="button" value="button text" />
instead of
<input type="button">button text</input>
-
You should rename your function. The function
click()
is already defined on a button (it simulates a click), and gets a higher priority then your method.
Note that there are a couple of suggestions here that are plain wrong, and you shouldn’t spend to much time on them:
- Do not use
onclick="https://stackoverflow.com/questions/5453937/javascript:myfunc()"
. Only use thejavascript:
prefix inside thehref
attribute of a hyperlink:<a href="https://stackoverflow.com/questions/5453937/javascript:myfunc()">
. - You don’t have to end with a semicolon.
onclick="foo()"
andonclick="foo();"
both work just fine. - Event attributes in HTML are not case sensitive, so
onclick
,onClick
andONCLICK
all work. It is common practice to write attributes in lowercase:onclick
. note that javascript itself is case sensitive, so if you writedocument.getElementById("...").onclick = ...
, then it must be all lowercase.