Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> JavaScript >> Displaying a message box in java script
Displaying a message box in java script
Displaying a message box in java script


by Awadhendra Tiwari on 3/9/2011 4:21:07 PM

Views: 4776       Comments: 1

Displaying a message box in java script

In this demonstration we learn that how to use Java Script to display a message box to the user. In Java Script there are two types of message box for displaying information. One is known as “alert” and another one is known as “confirm”. If you want to display an alert or warning regarding programs then we use alert () method for displaying message box and if we want to take some confirmation from user then we use confirm () method for displaying message box.

 Displaying message by using alert ()

Code:

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

    <script type="text/javascript">

        function showMessage() {

            alert("Wow! You have created first java script application.");

        }

    </script>

</head>

<body onload="showMessage()">

 

</body>

</html>

Here I had created a function named showMessage () which called at the load event of the body means to say at load event of the html document and display a message. Remember that for creating a function in java script I used function as a key word and onload is named of the event which is automatically called as well as html document is loaded.

Output of the following code snippet is as follows           

Message box in Java Script

Displaying message by using confirm () method

confirm (“<string message>”); method in java script is used to display confirm message box.

<head>

    <title></title>

    <script type="text/javascript">

        function showMessage() {

confirm("Wow! You have created first confirm message box.");

        }

    </script>

</head>

<body onload="showMessage()">

 

</body>

</html>

Output of the following code snippet is as follows

Message box in Java Script

Detecting which button is clicked in Confirm dialog box

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

    <script type="text/javascript">

        function showMessage() {

            var dd = confirm("Click any button to trace which button is clicked.");

            if (dd == true) {

                alert("You had clicked OK button on confirm dialog box.");

            }

            else {

                alert("You had clicked Cancel button on confirm dialog box")

            }

        }

    </script>

</head>

<body onload="showMessage()">

 

</body>

</html>

Output of the following code is as follows

Message box in Java Script

Message box in Java Script

Message box in Java Script

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Awadhendra TiwariRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 6562
Advertisement
MindStick SurveyManager
Advertise with Us
  
Copyright © 2013MindStick. All Rights Reserved.