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

rapid-development-with-cakephp.jpg

Rapid Development With CakePHP

Watch Now hibernate-the-ultimate-orm-framework.jpg

Hibernate-the ultimate ORM framework

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

Microsoft SharePoint-The Ultimate Enterprise Collaboration Platform

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

Introduction to JAVA/J2EE & SOA

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

Portal Development and Text Searching with Hibernate

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

Microsoft .NET Framework : An IntelliSense Way of Web Development

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

Microsoft Sharepoint 2013 : The Ultimate Enterprise Collaboration Platform

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

Node JS Express: Steps to Create Restful Web App

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

Node JS : Steps to Create Restful Web App

Watch Now implementing-web-services-in-java.jpg

Implementing Web Services In Java

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

MS .Net – An IntelliSense Way of Web Development

Watch Now mastering-regex-in-perl.jpg

Mastering Regex in Perl

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

PHP and MySQL : Server Side Scripting For Web Development

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

Microsoft SharePoint 2013 : The Ultimate Enterprise Collaboration Platform

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

Building Application With Ruby On Rails Framework

Watch Now introduction-to-javaj2ee-soa.jpg

Introduction to JAVA/J2EE & SOA

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

Building Web Application Using Spring Framework

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 effective-persistence-using-orm-with-hibernate.jpg

Effective Persistence Using ORM With Hibernate

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

Create Restful Web Application With Node.js Express

Watch Now

Recommended blogs for you

PHP-cURL-tutorial-1-300x175.jpg

PHP Curl Tutorial: Everything You Need To Know

Read Article Prime-number-program-in-Java-300x175.jpg

Know all about the Prime Number program in Java

Read Article Odd-Even-Program-In-C-300x175.jpg

How to Implement Odd & Even Program in C

Read Article no-image-1.png

Everything You Need To Know About Media Query In CSS

Read Article namespace-in-c-c-300x175.jpg

Everything You Need to Know about Namespace in C++

Read Article Loggers-in-java-300x175.png

What is logger in Java and why do you use it?

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

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

Read Article HTML-P-tag-300x175.jpg

All you need to Know about p tag in HTML

Read Article Gradients-in-CSS-300x175.jpg

All you need to know about Gradients in CSS

Read Article Checkbox-in-HTML-300x175.jpg

How to Create a Checkbox in HTML?

Read Article Method-overloading-and-overriding-in-java-300x175.jpg

What is the difference between Method Overloading And Overriding?

Read Article Do-While-Loop-in-java-300x175.jpg

What is a Do while loop in Java and how to use it?

Read Article Trim-function-in-PHP-300x175.jpg

How To Best Utilize Trim Function In PHP?

Read Article Java-Enum-Tutorial-1-300x175.jpg

Java Enum Tutorial: What is it and How to Implement it?

Read Article executor-service-in-java-300x175.png

What is ExecutorService in Java and how to create it?

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

What is Aggregation in Java and why do you need it?

Read Article Java-Method-Hiding-300x175.jpg

How to Implement Method Hiding in Java

Read Article Static-Method-In-Java-300x175.jpg

What Is Java Static Method?

Read Article Add-Two-Numbers-In-java-300x175.jpg

How To Implement Addition Of Two Numbers In Java?

Read Article Java-Programs-300x175.jpg

Basic Java Programs for Practice With Examples

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) Mastering Java Programming and Microservices Course by PwC Academy

Mastering Java Programming and Microservices ...

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

Spring Framework Certification Course

  • 13k Enrolled Learners
  • Weekend/Weekday
  • Live Class
Reviews 5 (4900) 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