How To Create An Alert In JavaScript? - Edureka
Có thể bạn quan tâm
- Blog
- How To Create An Alert In Java...
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)
- Bookmark





Copy Link! 16 / 31 Blog from JavaScript Become a Certified ProfessionalWhen 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- Pop-up Boxes in JavaScript
- Alert in JavaScript
- 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="<script>" title="<script>" />Output:

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="<style>" title="<style>" /> </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="<script>" title="<script>" /> </body> </html>Output:

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

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
Watch Now
Introduction to JAVA/J2EE & SOA
Watch Now
Effective Persistence Using ORM With Hibernate
Watch Now
Microsoft Sharepoint 2013 : The Ultimate Enterprise Collaboration Platform
Watch Now
Microsoft .NET Framework : An IntelliSense Way of Web Development
Watch Now
Learn Perl-the Jewel of Scripting Languages
Watch Now
Rapid Development With CakePHP
Watch Now
PHP & MySQL : Server-side Scripting Language for Web Development
Watch Now
Mastering Regex in Perl
Watch Now
Spring Framework : Introduction to Spring Web MVC & Spring with BigData
Watch Now
Building Web Application Using Spring Framework
Watch Now
Microsoft SharePoint 2013 : The Ultimate Enterprise Collaboration Platform
Watch Now
Responsive WEB APP using cakePHP
Watch Now
Service-Oriented Architecture With Java
Watch Now
Building Application With Ruby On Rails Framework
Watch Now
Introduction to JAVA/J2EE & SOA
Watch Now
Node JS Express: Steps to Create Restful Web App
Watch Now
Create Restful Web Application With Node.js Express
Watch Now
Microsoft SharePoint-The Ultimate Enterprise Collaboration Platform
Watch Now
A Day In The Life Of A Node.js Developer
Watch NowRecommended blogs for you

What Is Header Location In PHP?
Read Article
How To Implement Arrays In C++?
Read Article
Swing In Java : Know How To Create GUI With Examples
Read Article
What is JIT in Java? – Understanding Java Fundamentals
Read Article
Synchronization in Java: What, How and Why?
Read Article
What is Dynamic Array in Java?
Read Article
What is the basic Structure of a Java Program?
Read Article
How to implement Perfect Number in Java?
Read Article
Advanced JavaScript Tutorial: The Best Guide to Advanced Aspects
Read Article
Why Java is a Secure language?
Read Article
Bitset In Java: All You Need To know About Bitset Methods In Java
Read Article
How to use Spring MVC Themes
Read Article
Object Oriented Programming – Java OOPs Concepts With Examples
Read Article
Web Developer Roadmap: Front End, Back End, Full Stack
Read Article
Java Interview Questions and Answers
Read Article
All you Need to Know About Implements In Java
Read Article
How to Become a Front End Developer?
Read Article
Struts 2 Tutorial – One Stop Solution for Beginners
Read Article
this Keyword In Java – All You Need To Know
Read Article
Linked List in Java: How to Implement a Linked List in Java?
Read Article Comments 0 CommentsJoin the discussionCancel reply
Trending Courses in Programming & Frameworks

Full Stack Development Internship Program
- 29k Enrolled Learners
- Weekend/Weekday
- Live Class

Java Course Online
- 82k Enrolled Learners
- Weekend/Weekday
- Live Class

Python Scripting Certification Training
- 15k Enrolled Learners
- Weekend
- Self Paced

Flutter App Development Certification Course
- 13k Enrolled Learners
- Weekend/Weekday
- Live Class

Node JS Course with Certification
- 11k Enrolled Learners
- Weekend/Weekday
- Live Class

Spring Framework Certification Course
- 13k Enrolled Learners
- Weekend/Weekday
- Live Class

Mastering Java Programming and Microservices ...
- 1k Enrolled Learners
- Weekend/Weekday
- Live Class

Advanced Java Certification Training
- 7k Enrolled Learners
- Weekend/Weekday
- Self Paced

Comprehensive Java Course Certification Train ...
- 19k Enrolled Learners
- Weekend/Weekday
- Self Paced

Data Structures and Algorithms using Java Int ...
- 31k Enrolled Learners
- Weekend/Weekday
- Live Class
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 & ArchitectureSubscribe to our Newsletter, and get personalized recommendations.
Already have an account? Sign in.
20,00,000 learners love us! Get personalised resources in your inbox.
Sign up with Gmail Sign up with FacebookOR
Password must haveAt least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
SIGN UP Already have an Edureka Account? Login Forgot Password? LOGIN Don’t have edureka account? Sign Up resend ? Password must haveAt least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
reset password Don’t have edureka account? Sign Up reset password Don’t have edureka account? Sign Up Send Code Don’t have edureka account? Sign UpAwesome
We have recieved your contact details.
You will recieve an email from us shortly.
How to Create an Alert in JavaScript?
edureka.co
Từ khóa » Html Js Alert Button
-
Tryit Editor V3.7 - JavaScript Alert - W3Schools
-
JavaScript Popup Boxes - W3Schools
-
WebD2: Using JavaScript To Show An Alert - University Of Washington
-
JavaScript Alert [Examples And Usage] - Alvaro Trigo
-
JavaScript Alert Messages And Confirmation Messages
-
How To Make A Html Button Clickable And To Show Alert On It
-
Button Onlick Show Alert Box - Javascript - Stack Overflow
-
How Does JavaScript Onclick Alert Work? - EduCBA
-
JavaScript - Create An Alert On Clicking An HTML Button - Tutorialspoint
-
JavaScript Alert() - Javatpoint
-
Alerts - Bootstrap
-
JavaScript Message Boxes: Alert(), Confirm(), Prompt()
-
Display Alert Message On Button Click Event Using JavaScript
-
JavaScript Alert Box