Articles → JAVASCRIPT → Alerts in JavaScript

Alerts in JavaScript












Alert box






alert(“<message>”);




alert("Hi,this message is for information purpose.");
  



Picture showing the alert box in JavaScript

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
}




Picture showing the confirm box in JavaScript

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");
 }






Picture showing the prompt box in JavaScript

Click to Enlarge




Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, March 22, 2011

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250