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.

RajeshKdev
  • 6,365
  • 6
  • 58
  • 80
  • Your title says `click`, but the code says `clic` (no `k`). Which one are you asking about? – Barmar Feb 03 '15 at 00:35
  • @Barmar, he asked why when he use `clic` instead of `click` works, why can't he name his function `click`. – invisal Feb 03 '15 at 00:38
  • Please put the code you're having trouble with in the question, not the code that works. – Barmar Feb 03 '15 at 00:40

2 Answers2

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>
Terik Brunson
  • 187
  • 1
  • 13
-3

Try this without the parenthesis

onclick="clic"

stuli
  • 47
  • 10
  • 1
    That won't do anything. The contents of `onXXX` is interpreted as a Javascript statement. – Barmar Feb 03 '15 at 00:36