Tuesday, September 1, 2015

Javascript Popups Box



javascript has three types of popup box 1)alert box  2)Commfirm box and 3)prompt box

Alert Box



An alert box is often used if you want to make sure information comes through to the user.

alert command

alert('Hello Pakistan');

javascript is a case sensitive language so be careful for typing. if you are type (Alert) so it's wrong in javascript here

javascript considered diffrent meaning

 alert("hello pakistan"); different meaning.
 Alert('Hello Pakistan'); different meaning.

<!DOCTYPE html>
<html>
<head>
     <title></title>
</head>
<body>

     <p>Click the button and see how alert in web browser</p>

     <button onclick="myFunc()">Show Alert</button>

<script>
function myFunc() {
    alert("Hello Pakistan!");
}
</script>

</body>
</html>

Confirm Box

A confirm box is often used if you want the user to verify or accept something. When a confirm box pops up, the user will

How to use Conform Box

<!DOCTYPE html>
<html>
<head>
     <title></title>
</head>
<body>

<p>Click the button and see how Confirm box in web browser</p>

<button onclick="myFunc()">Show Confirm </button>

<p id="demo"></p>

<script>
function myFunc() {
    var x;
    if (confirm("Press a button!") == true) {
        x = "You pressed OK!";
    } else {
        x = "You pressed Cancel!";
    }
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Prompt Box



A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up,

How to use Prompt Box

<!DOCTYPE html>
<html>
<body>

<p>Click the button and see how prompt box in web browser</p>

<button onclick="myFunc()">Use prompt box</button>

<p id="demo"></p>

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

</body>
</html>

No comments:

Post a Comment

Swift Start Here