views:

201

answers:

4

I'm stumped, I can't seem to get this simple Javascript function to get called. Thanks!

 <html>
 <head>


<script type="text/javascript">

    function increase()
    {
        alert(" the button was pressed");
    }

</script>         
 </head>

 <body>


 <form action="Test.html" method="post">

   <input type="submit" onclick="increase();" />

</form>   

 </body>
 </html>
A: 

Have you tried this? You need to place JavaScript between script tags:

<script type="text/javascript">
    function increase() { alert(" the button was pressed"); } 
</script>
Praveen Angyan
how about the <form>Thanks
Server_Mule
A: 

Apart from what Praveen said, wich I agree, there are good beginner tutorials here and here.

eKek0
thanks! great site recommendations!
Server_Mule
you're welcome. Read this too http://stackoverflow.com/questions/44664/is-reputation-important
eKek0
+1  A: 

Try this:

<input type="button" id="buttonId">Button</input>

<script language="javascript">
    function increase() { alert(" the button was pressed"); } 

    document.getElementById("buttonId").onClick=increase;
</script>
Spike Williams
+2  A: 

It is hard to tell where you are going wrong. It looks like you are just defining a function. This will case the increase function to run when the page is loaded:

<script type="text/javascript">
  function increase() {
    alert(" the button was pressed");
  }
  increase();
</script>

This will run the function when a button is pressed.

<script type="text/javascript">
  function increase() {
    alert(" the button was pressed");
  }
</script>
<button onclick="increase()">text</button>

It sounds like you are just getting started, and that is awesome. I would also suggest getting a book. A few years ago, I read DOM Scripting by Jeremy Keith, it was okay. Also, try looking around online for tutorials.

Buddy
does the button have to be in a Form tag?if so, how should it look,Thanks
Server_Mule
Nope - doesn't have to be a part of a form.
Tony k