How To Create An Alert In JavaScript? - Edureka

  1. Blog
  2. How To Create An Alert In Java...
Java/J2EE and SOA (344 Blogs) Become a Certified Professional AWS Global Infrastructure
JavaScript
  • What is JavaScript – All You Need To Know About JavaScript
  • JavaScript Tutorial for Beginners : A Complete Guide
  • What is a JavaScript Variable and How to declare it?
  • What are JavaScript Operators and its Types?
  • What are JavaScript Methods and How to use them?
  • What is indexOf in JavaScript and how does it work?
  • What is a JavaScript Class and how to use it?
  • forEach Loop in JavaScript: One Stop Solution for beginners
  • What are Events in JavaScript and how they are handled?
  • What is Try Catch in JavaScript and how it works?
  • How To Implement JavaScript Trim Method?
  • Java vs JavaScript: What are the differences?
  • What are JavaScript Reserved Words and Keywords?
  • What is the JavaScript MVC Architecture and How does it Work?
  • Top 10 Most Popular JavaScript Frameworks
  • How to Create an Alert in JavaScript?
  • TypeScript vs JavaScript: What are the differences?
  • Important JavaScript Functions You Need to Know About
  • What are the top 20 Javascript String Functions and how to use them?
  • How to submit a form in JavaScript?
  • Removing Elements From An Array In JavaScript
  • How to Build a JavaScript Calculator?
  • How To Best Utilize Onclick In JavaScript?
  • Splice Array in JavaScript: All you need to know Array.Splice() Method
  • How to Implement JavaScript Date Methods?
  • String Concatenation In JavaScript: All you need to know about String concat()
  • Event Bubbling and Event Capturing In JavaScript: All you need to know
  • How to Implement String Length in JavaScript
  • Unshift JavaScript : Know How to Use Unshift() Method in Array
  • What is SetInterval in JavaScript and How Does it Work?
  • Advanced JavaScript Tutorial: The Best Guide to Advanced Aspects
jQuery
  • jQuery Tutorial – A Complete Guide For Beginners
  • Angular Routing: A Complete Guide for Beginners
Interview Questions
  • Top 90+ JavaScript Interview Questions and Answers for 2025
  • JavaScript Projects- Know How to Build Your Own Web Application

Programming & Frameworks

Topics Covered
  • C Programming and Data Structures (16 Blogs)
  • Comprehensive Java Course (5 Blogs)
  • Java/J2EE and SOA (341 Blogs)
  • Spring Framework (9 Blogs)
SEE MORE Programming & Frameworks blog posts How to Create an Alert in JavaScript? Last updated on Feb 25,2025 43.3K Views Shareimage not found!WhatsAppimage not found!Linkedinimage not found!Twitterimage not found!Facebookimage not found!Redditimage not found!Copy Link! edureka edureka
  • Bookmark
image not found!image not found!image not found!image not found!image not found!image not found!Copy Link! 16 / 31 Blog from JavaScript Become a Certified Professional

When you open any website, you might see alert pop-ups at times. These JavaScript alert boxes are useful for alerting users to something important. When a JavaScript alert box is triggered, a small box pops up and displays the text that you specify in your JavaScript code. In this article, we will see how the alert in JavaScript works, in the following sequence:

Table of Content
  1. Pop-up Boxes in JavaScript
  2. Alert in JavaScript
  3. How to Create an Alert in JavaScript?

Let’s begin.

Pop-up Boxes in JavaScript

In JavaScript, you can find three kinds of popup boxes:

  • Alert box- An alert box is mostly used to make sure information comes through to the user. When an alert box pops up, you need to click “OK” to proceed.

  • Confirm box- A confirm box is mostly used to verify or accept something for the user. When a confirm box pops up, the user needs to click either “OK” or “Cancel” to proceed. If the user clicks “OK”, the box returns true. If the user clicks “Cancel”, the box returns false.

  • Prompt box- A prompt box is used by the user to input a value before entering a page. When a prompt box pops up, the user needs to click either “OK” or “Cancel” to proceed after entering an input value. If the user clicks “OK” the box returns the input value. If the user clicks “Cancel” the box returns null.

These were the different types of popup boxes. So, let’s get into the depth of the alert box and see how you can create an alert box in JavaScript.

Alert in JavaScript

The alert() method in JavaScript displays an alert box with a specified message and an OK button. It is often used to make sure that information comes through to the user.

The alert box takes the focus away from the current window and forces the browser to read the message. So, you should avoid overusing this method, as it prevents the user from accessing other parts of the page until the box is closed.

Syntax:

alert(message)

Here, the message is a string type that specifies the text to display in the alert box, or an object converted into a string and displayed. It is optional.

Example:

<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%3E%0Afunction%20myFunction()%20%7B%0Aalert(%22This%20is%20an%20Alert!%22)%3B%0A%7D%0A%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" />

Output:

Alert box - alert in javascript - edureka

How to Create an Alert in JavaScript?

The alert() method in JavaScript displays an alert box. It displays a specified message along with an OK button and is generally used to make sure that the user gets the information. It returns a string which represents the text to display in the alert box. Let’s take an example and see how to create an alert in JavaScript:

<!DOCTYPE html> <html> <head> <title> Alert() Method in JavaScript </title> <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cstyle%3E%0Ah1%20%7B%0Acolor%3A%20Blue%3B%0A%7D%0A%0Ah2%20%7B%0Afont-family%3A%20Impact%3B%0A%7D%0A%0Abody%20%7B%0Atext-align%3A%20center%3B%0A%7D%0A%3C%2Fstyle%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;style&gt;" title="&lt;style&gt;" /> </head> <body> <h1>Welcome to Edureka</h1> <h2>Alert in JavaScript</h2> <p> To Display the alert message, click on the "Show Alert Message" button: </p> <button ondblclick="myalert()"> Show Alert Message </button> <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%3E%0Afunction%20myalert()%20%7B%0Aalert(%22This%20is%20the%20Alert%20Message!%22)%3B%0A%7D%0A%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" /> </body> </html>

Output:

After you double click the button, you will get the following output:

Output 2- Alert in JavaScript - edureka

With this, we have come to the end of our article. I hope you understood what is an alert in JavaScript and how you can create an alert box. If you’re just beginning, then watch at this Java Tutorial to Understand the Fundamental Java Concepts.

Check out our Full Stack java Developer Training which comes with instructor-led live training and real-life project experience. This training makes you proficient in skills to work with back-end and front-end web technologies. It includes training on Web Development, jQuery, Angular, NodeJS, ExpressJS, and MongoDB.

Got a question for us? Please mention it in the comments section of “Alert in JavaScript” blog and we will get back to you.

Recommended videos for you

portal-development-and-text-searching-with-hibernate.jpg

Portal Development and Text Searching with Hibernate

Watch Now introduction-to-javaj2ee-soa.jpg

Introduction to JAVA/J2EE & SOA

Watch Now effective-persistence-using-orm-with-hibernate.jpg

Effective Persistence Using ORM With Hibernate

Watch Now microsoft-sharepoint-2013-the-ultimate-enterprise-collaboration-platform.jpg

Microsoft Sharepoint 2013 : The Ultimate Enterprise Collaboration Platform

Watch Now microsoft-net-framework-an-intellisense-way-of-web-development.jpg

Microsoft .NET Framework : An IntelliSense Way of Web Development

Watch Now learn-perl-the-jewel-of-scripting-languages.jpg

Learn Perl-the Jewel of Scripting Languages

Watch Now rapid-development-with-cakephp.jpg

Rapid Development With CakePHP

Watch Now php-mysql-server-side-scripting-language-for-web-development.jpg

PHP & MySQL : Server-side Scripting Language for Web Development

Watch Now mastering-regex-in-perl.jpg

Mastering Regex in Perl

Watch Now spring-framework-introduction-to-spring-web-mvc-spring-with-bigdata.jpg

Spring Framework : Introduction to Spring Web MVC & Spring with BigData

Watch Now building-web-application-using-spring-framework.jpg

Building Web Application Using Spring Framework

Watch Now microsoft-sharepoint-2013-the-ultimate-enterprise-collaboration-platform.jpg

Microsoft SharePoint 2013 : The Ultimate Enterprise Collaboration Platform

Watch Now responsive-web-app-using-cakephp.jpg

Responsive WEB APP using cakePHP

Watch Now service-oriented-architecture-with-java.jpg

Service-Oriented Architecture With Java

Watch Now building-application-with-ruby-on-rails-framework.jpg

Building Application With Ruby On Rails Framework

Watch Now JAVA-J2EE-WEBINAR-600x3501_-300x175.png

Introduction to JAVA/J2EE & SOA

Watch Now node-js-express-steps-to-create-restful-web-app.jpg

Node JS Express: Steps to Create Restful Web App

Watch Now create-restful-web-application-with-node-js-express.jpg

Create Restful Web Application With Node.js Express

Watch Now microsoft-sharepoint-the-ultimate-enterprise-collaboration-platform.jpg

Microsoft SharePoint-The Ultimate Enterprise Collaboration Platform

Watch Now a-day-in-the-life-of-a-node-js-developer.jpg

A Day In The Life Of A Node.js Developer

Watch Now

Recommended blogs for you

header-location-in-php-300x175.jpg

What Is Header Location In PHP?

Read Article Arrays-In-C-300x175.jpg

How To Implement Arrays In C++?

Read Article Swing-In-Java-300x175.jpg

Swing In Java : Know How To Create GUI With Examples

Read Article JIT-in-Java-300x175.jpg

What is JIT in Java? – Understanding Java Fundamentals

Read Article Synchronization-in-Java_-300x175.jpg

Synchronization in Java: What, How and Why?

Read Article Dynamic-Array-in-Java-300x175.jpg

What is Dynamic Array in Java?

Read Article Structure-Of-A-Java-Program-1-300x175.jpg

What is the basic Structure of a Java Program?

Read Article Perfect-number-in-Java-300x175.jpg

How to implement Perfect Number in Java?

Read Article Advanced-JavaScript-Tutorial-1-300x175.jpg

Advanced JavaScript Tutorial: The Best Guide to Advanced Aspects

Read Article Why-java-is-secure-300x175.png

Why Java is a Secure language?

Read Article bitset-in-java-300x175.jpg

Bitset In Java: All You Need To know About Bitset Methods In Java

Read Article Theam+2-300x175.gif

How to use Spring MVC Themes

Read Article Object-Oriented-Programming-300x175.png

Object Oriented Programming – Java OOPs Concepts With Examples

Read Article Web-Developer-Roadmap-Edureka-300x152.jpg

Web Developer Roadmap: Front End, Back End, Full Stack

Read Article Java-Interview-Question-300x175.png

Java Interview Questions and Answers

Read Article Implements-in-Java-300x175.jpg

All you Need to Know About Implements In Java

Read Article How-to-Become-a-Front-End-Developer-300x175.jpg

How to Become a Front End Developer?

Read Article Struts-Tutorial-300x175.jpg

Struts 2 Tutorial – One Stop Solution for Beginners

Read Article This-keyword-in-Java-1-300x175.jpg

this Keyword In Java – All You Need To Know

Read Article Linked-List-in-Java-2-300x175.jpg

Linked List in Java: How to Implement a Linked List in Java?

Read Article Comments 0 Comments

Join the discussionCancel reply

Trending Courses in Programming & Frameworks

Full Stack Development Internship Program

Full Stack Development Internship Program

  • 29k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (11300) Java Course Online

Java Course Online

  • 82k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 4 (30350) Python Scripting Certification Training

Python Scripting Certification Training

  • 15k Enrolled Learners
  • Weekend
  • Self Paced
Reviews 5 (5850) Flutter App Development Certification Course

Flutter App Development Certification Course

  • 13k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (4800) Node JS Course with Certification

Node JS Course with Certification

  • 11k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (3850) Spring Framework Certification Course

Spring Framework Certification Course

  • 13k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (4900) Mastering Java Programming and Microservices Course by PwC Academy

Mastering Java Programming and Microservices ...

  • 1k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (7) Advanced Java Certification Training

Advanced Java Certification Training

  • 7k Enrolled Learners
  • Weekend/Weekday
  • Self Paced
Reviews 5 (2800) Comprehensive Java Course Certification Training

Comprehensive Java Course Certification Train ...

  • 19k Enrolled Learners
  • Weekend/Weekday
  • Self Paced
Reviews 5 (7250) Data Structures and Algorithms using Java Internship Program

Data Structures and Algorithms using Java Int ...

  • 31k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (12050)

Browse Categories

Artificial IntelligenceAWSBI and VisualizationBig DataBlockchainBusiness ManagementCloud ComputingCyber SecurityData ScienceData Warehousing and ETLDatabasesDevOpsDigital MarketingEnterpriseFront End Web DevelopmentHuman Resource ManagementInterview QuestionsMobile DevelopmentOperating SystemsOperations ManagementProduct ManagementProject Management and MethodologiesRobotic Process Automationseo interview questionSoftware TestingStrategy and LeadershipSupply Chain ManagementSystems & Architecture webinar REGISTER FOR FREE WEBINAR Years of Experience*Student0-2 Years2-5 Years5-10 Years10+ Years REGISTER NOW webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

Google Sign up with Google facebook Signup with Facebook

Already have an account? Sign in.

20,00,000 learners love us! Get personalised resources in your inbox.

with Gmail with Facebook

OR

Password must have

At least 1 upper-case and 1 lower-case letter

Minimum 8 characters and Maximum 50 characters

SIGN UP Forgot Password? LOGIN resend ? Password must have

At least 1 upper-case and 1 lower-case letter

Minimum 8 characters and Maximum 50 characters

reset password reset password Send Code imagReshape Your Career! Name* Email ID* Phone Number* Your Total Work Experience* Years of Experience*Student0-2 Years2-5 Years5-10 Years10+ Years Apply Now

Awesome

We have recieved your contact details.

You will recieve an email from us shortly.

imageMain headingsub heading Click to avail "PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc. image not found! image not found!

How to Create an Alert in JavaScript?

edureka.co

image not found! Whatsapp image not found! Linkedin image not found! Twitter image not found! Facebook image not found! Reddit Copy Link image not found!

Từ khóa » Html Js Alert Button