Computer >> Computer tutorials >  >> Programming >> Javascript

How to call JavaScript function in an alert box?


To call a JavaScript function in an alert box, you can try to run the following code −

Example

<!DOCTYPE html>
<html>
   <body>
      <script>
         function myFunction(warning) {
            alert(warning);
            catchedAlert();
         }
         function catchedAlert() {
            alert('Alert called!');
         }
      </script>
      <button onclick="myFunction('This is an alert box!')">Click me!</button>
   </body>
</html>