0

Why doesn't this work?

html :

<html>
 <head>
  <title>test</title>
 </head>
 <body>
  <button onclick="test21()">test</button>
 </body>
</html>

javascript:

function test21(){
    console.log("yey");
}
1

3 Answers 3

1

That works fine. Here's a JSBin to prove it.

http://jsbin.com/luxesazibi/edit?html,output

More than likely you haven't loaded your script in your HTML. Where are you putting your javascript?

Sign up to request clarification or add additional context in comments.

Comments

0

You can create a single function that calls both of those, and then use it in the event.

function myFunction(){
    pay();
    cls();
}

And then, for the button:

<input id="btn" type="button" value="click" onclick="myFunction();"/>

Comments

0

You have not included the script in html file.

<html>
 <head>
  <title>test</title>
   <script>
     function test21(){
      console.log("yey");
      }
   </script>
 </head>
 <body>
  <button onclick="test21()">test</button>
 </body>
</html>

Above code snippet will run fine.
Use inspector (ctrl+shift+I) to launch console and click on the button to get results.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.