Following different alert boxes
1) Simple Alert box
2) Confirm box
3) Prompt box
1) Simple Alert Box:
following code for alert box:
<html>
<body>
<h2>JavaScript Alert</h2>
<button onclick="myFunction()">Check It </button>
<script>
function myFunction() {
alert("alert box demo..!");
}
</script>
</body>
</html>
Output:
2) Confirm Alert Box:
following code for confirm alert box:
<html>
<body>
<h2>JavaScript Confirm Box</h2>
<button onclick="myFunction()">Check it</button>
<p id="demo"></p>
<script>
function myFunction() {
var txt;
if (confirm("Press a button!")) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>
Output:
3) Prompt Alert Box:
following code for prompt alert box:
<html>
<body>
<h2>JavaScript Prompt</h2>
<button onclick="myFunction()">Check it</button>
<p id="demo"></p>
<script>
function myFunction() {
var txt;
var person = prompt("Please enter your name:", "fruxinfo");
if (person == null || person == "") {
txt = "User cancelled the prompt.";
} else {
txt = "Hello " + person + "! How are you..?";
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>
Output:
Fruxinfo Pvt. Ltd.

0 coment�rios: