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>
-
Well, you're not calling it anywhere we can see. That would explain the problem.Chuck– Chuck2009年05月08日 23:59:25 +00:00Commented May 8, 2009 at 23:59
5 Answers 5
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.
2 Comments
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>
Comments
Have you tried this? You need to place JavaScript between script tags:
<script type="text/javascript">
function increase() { alert(" the button was pressed"); }
</script>
Comments
1 Comment
in your code the form submits as you click the button.
what you will have to do is return false; so that the form doesnt submit..
<form action="#" method="POST">
<input type="submit" onclick="return false; increase();">
</form>