Articles → JAVASCRIPT → Alerts In Javascript
Alerts In Javascript
- Alert box
- Confirm box
- Prompt box
Alert Box
alert("Hi,this message is for information purpose.");
Click to Enlarge
Confirm Box
if (confirm("<confirmation_message>") == true) {
// Do Something
}
else {
// Do something else
}
if(confirm("Are you sure you want to save your personal information?") == true) {
// Do Something
}
else{
// Do Something else
}
Click to Enlarge
Prompt Box
var variable_name = prompt("<message>","<default_string>");
var age = prompt("Please enter your age", "18");
if (parseInt(age) >= 18) {
alert("You are eligible to vote");
} else {
alert("Sorry,you can't vote");
}
Click to Enlarge