JavaScript Program to Show Alert Message on Button Click

Write a JavaScript program to show alert message on button click.



Source Code
<html>

<head>
    <title>JavaScript event example</title>
    <script type="text/javascript">
        function sayHello() {
            alert("Hello World!")
        }
    </script>
</head>

<body>
    <p>Click the button to see result</p>
    <form>
        <input type="button" onclick="sayHello()" value="Say Hello" />
    </form>
</body>

</html>
Output





"Coding Hub - Learn to code" app now available on Google Play Store