Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Javascript popup boxes

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 141
    Comment on it

    Hello Readers

    Javascript has three kind of popup boxes:

    1. Alert box
    2. Confirm box.
    3. Prompt box.

    1. Alert box:
    If you want the information comes through the user then we use the alert popup box.

    Syntax of alert box:

    window.alert("sometext");
    

    It can be also used without window prefix.

    For Example:

    <html>
    <body>
    <p>Click the button to display an alert box:</p>
    <button onclick="myFunction()">Try it</button>
    <script>
    function myFunction() {
        alert("I am an alert box!");
    }
    </script>
    </body>
    </html>
    

    1. Confirm Box:
    If you want the user to verify or accept something then we use the confirm box. So, when the confirm box pops up user have to click either "ok" or "cancel" to proceed.

    If the user clicks "ok", the box returns true. If the user clicks "cancel", the box returns false.

    Syntax of confirm box:

    window.confirm("sometext");
    

    We also use window.confirm() method without the window prefix.

    For Example:

    var r = confirm("Press a button");
    if (r == true) {
        x = "You pressed OK!";
    } else {
        x = "You pressed Cancel!";
    }
    

    1. Prompt Box:
    If you want the user to input a value before entering into the page then we use the prompt box. So, when a prompt box pops up, the user will have to click either "ok" or "cancel" to proceed after entering an input value. If the user clicks "ok" the box returns the input value if the user clicks "cancel" the box returns null.

    Syntax of prompt box:

    window.prompt("sometext","defaultText");
    

    We also use window.prompt() method without the window prefix.

    For Example:

    var person = prompt("Please enter your name", "Harry Potter");
    if (person != null) {
        document.getElementById("demo").innerHTML ="Hello " + person + "! How are you today?";
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: