2

Hi I'm trying to learn Javascript and I was trying to make window pop-up but I tried to do it with a function. Is there a rule where you can't name a function click?

<script type="text/javascript">
    function click() {
        alert("boom!!!");
    }

</script> 

<form>
    <input type="button" value="touch me" onclick="click()" />
</form>

I'm wondering why it does not work because even if click is a word that already exist in javascript, I thought that the "" would tell the browser that it is the function click that I just created.

3
  • Your title says click, but the code says clic (no k). Which one are you asking about? Commented Feb 3, 2015 at 0:35
  • @Barmar, he asked why when he use clic instead of click works, why can't he name his function click. Commented Feb 3, 2015 at 0:38
  • Please put the code you're having trouble with in the question, not the code that works. Commented Feb 3, 2015 at 0:40

2 Answers 2

1

I think you're just missing a ";" But no, I don't think that click is a reserved word in JavaScript.

<script type="text/javascript">
function clic() {
    alert("boom!!!");
}

</script> 

 <form>
<input type="button" value="touch me" onclick="clic();" />
</form>
Sign up to request clarification or add additional context in comments.

2 Comments

See this detailed answer. Click isn't a reserved word necessarily but it's defined in the lexical scope. window.click() works fine.
I didn't either until I looked it up. Otherwise, your answer is correct.
-3

Try this without the parenthesis

onclick="clic"

1 Comment

That won't do anything. The contents of onXXX is interpreted as a Javascript statement.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.