Program for prompt box |HTML|

Introduction

    In the realm of web development, user interaction plays a pivotal role in creating engaging and dynamic experiences. One commonly used tool to interact with users is the JavaScript prompt box. In this blog post, we'll delve into the usage and implementation of prompt boxes in JavaScript, showcasing how they can enrich user engagement on web pages.


Code

    
     
    <html>
    <head>
        <script type="text/javascript">
        function show_prompt() {
            var name = prompt("Please enter your name", "Anu");
            if (name !== null && name !== "") {
            document.write("<p>Hello " + name + "! How are you?</p>");
            }
        }
        </script>
    </head>
    <body>
        <input type="button" onClick="show_prompt()" value="Show"/>
    </body>
    </html>
       
     


Output





In this example, we've defined a JavaScript function show_prompt() that gets triggered when the button is clicked. It opens a prompt box asking the user to enter their name. If the user inputs a name and clicks "OK", a greeting message is displayed on the page.

Conclusion

     JavaScript prompt boxes are a valuable tool for enhancing user interaction and collecting user input on web pages. When used judiciously, they can contribute to creating more interactive and user-friendly experiences. However, it's essential to use them sparingly and ensure they complement the overall design and functionality of the webpage. With a solid understanding of prompt boxes, you can elevate the interactivity of your web applications and provide users with a more engaging experience. Happy coding!

Post a Comment

0 Comments