Articles → JAVASCRIPT → Alerts In Javascript

Alerts In Javascript





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

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