I have a JavaScript code that has an HTML page with a button. I have a function called 'click' (function) which click on the button. The code for the button is as follows:
& lt; Input type = "button" onClick = "click ()" & gt; Button text & lt; / Input & gt; The problem is that when the button is clicked, the function is not called. What am I doing wrong here? Thank you
Two comments:
-
You should write < / P>
& lt; Input type = "button" value = "button text" /> & lt; Input type = "button" & gt; Instead of button text, & lt; / Input & gt;
-
You should rename your function. The function click () is already defined on a button (this limits one click), and gives a higher priority to your preference. Note that here are some suggestions that are simple, and you should not spend too much time on them:
-
Onclick = "javascript: myfunc ()" do not use . Use the Javascript: prefix inside the href attribute of the hyperlink only: & lt; A href = "javascript: myfunc ()" & gt; - You do not have to end with a semicolon
onclick = "foo ()" and onclick = "foo ();" Both work is fine. - The incidence of the event attributes in HTML are not sensitive, so
onclick , onClick and ONCLICK do all the work in lowercase Typical writing of functions is: onclick . Note that Javascript itself is case sensitive, so if you type document.getElementById ("..."). Onclick = ... , then it should all lowercase .
Comments
Post a Comment