Instructables

I can't get my my javascript code to work!

I have been trying for days to get just the simplest of javascript working on my webpage but no matter what I try nothing happens. I am trying to display a button and then make a pop-up message when the user clicks it. I cannot stress how much frustration I have gone through just trying to make it do anything. I am writing it in mozilla Kompozer and testing it in mozilla Firefox.

Here is the full code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 

<html> 

<head> 

<script type="text/javascript"> 

function click() 

{ 

alert("You clicked!"); 

} 

</script> 

<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> 

</head> 

<body> 

<input name="click" value="Click me!" onclick="click()" type="button"> 

</body> 

</html>
Please, if you can give me any help regarding this, I thank you greatly. I am near to beating my head against my CRT.


Picture of I can't get my my javascript code to work!
mwrenfro3 years ago
Rename the function something other than "click()" and change the onclick accordingly. click() is apparently a reserved function for UI elements or similar.

.  You beat me to it.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
   <script type="text/javascript">
      function myClick() {
         alert("You clicked!");
      }
   </script>
   <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
</head>
<body>
   <form>
      <input name="click" value="Click me!" onclick="myClick()" type="button" />
   </form>
</body>
</html>
dungeon runner (author) 3 years ago
Aha! Thanks!
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!