1

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>
trinaldi
  • 2,872
  • 2
  • 32
  • 37

2 Answers2

1

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>
Luís Ramalho
  • 10,018
  • 4
  • 52
  • 67
0

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)

clota974
  • 495
  • 5
  • 16