Reputation: 71
I am using html to try to create an calculator I am using HTML for the buttons to run javascript.
<form method="get" action="a.js">
<button onclick="a.js">addition</button>
</form>
Upvotes: 1
Views: 335
Reputation: 10218
Here's a basic example to get you started:
<!DOCTYPE html>
<html>
<head>
<title>Simple Button Click</title>
</head>
<body>
<form method="get" action="a.js">
<button onclick="handleClick()">addition</button>
</form>
<script type="text/javascript">
function handleClick() {
console.log("clicked.");
}
</script>
</body>
</html>
function handleClick() {
console.log("clicked.");
}
<form method="get" action="a.js">
<button onclick="handleClick()">addition</button>
</form>
Upvotes: 1
Reputation: 505
Indeed, when you click the submit button, it opens the a.js
file instead of doing what you want.
If you want to send a request (as you provided a form), you need a server to process the data.
In your case, you may want to :
1- Import your script with the script
tag
2- Replace your form attribute with action="#"
3- Call the function with onclick='myFunction()
in your button tag (onclick
lowercase according to w3schools)
Upvotes: 0