JavaScript alert - Dialog box
Description
alert() is a simple function to display a message to a dialog box (also called alert box). Here is a simple example to display a text in the alert box.
Code
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset=utf-8>
- <title>Javascript alert box example-1</title>
- </head>
- <body>
- <h1 style="color: red">JavaScript alert() box example</h1>
- <hr />
- <script type="text/javascript">
- alert("This is a alert box");
- </script>
- </body>
- </html>
Let's puts some variables in the alert box.
Code
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset=utf-8>
- <title>JavaScript alert box example-2</title>
- </head>
- <body>
- <h1 style="color: red">JavaScript alert() box example</h1>
- <hr />
- <script type="text/javascript">
- mess1='Highest marks in Mathematics : ';
- math=99;
- alert(mess1+math);
- </script>
- </body>
- </html>
JavaScript prompt - Dialog box
Description
The alert() method can not interact with the visitor. To interact with the user we use prompt(), which asks the visitor to input some information and stores the information in a variable.
See the following web document.
Code
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset=utf-8>
- <title>JavaScript prompt() example-2</title>
- </head>
- <body>
- <script type="text/javascript">
- visiter_name = prompt("Input your name : ")
- if(visiter_name != null && visiter_name != "")
- alert("Your Name is : "+visiter_name);
- else
- alert("Blank name ...!")
- </script>
- </body>
- </html>
JavaScript confirm - Dialog box
Description
Confirm() displays a dialog box with two buttons, OK and Cancel and a text as a parameter. If the user clicks on OK button, confirm() returns true and on clicking Cancel button, confirm() returns false.
See the following web document.
Code
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset=utf-8>
- <title>JavaScript confirm box example </title>
- </head>
- <body>
- <h1 style="color: red">JavaScript confirm() box example</h1>
- <hr />
- <script type="text/javascript">
- mess1='Press Ok to Continue.';
- math=99;
- x = confirm(mess1);
- if (x == true)
- {
- alert("You have clicked on Ok Button.");
- }
- else
- {
- alert("You have clicked on Cancel Button."); }
- </script>
- </body>
- </html>
Supported Browser
Internet Explorer 7 | Firefox 3.6 | Google Chrome 7 | Safari 5.0.1 | Opera 10 |
Yes | Yes | Yes | Yes | Yes |
No comments:
Post a Comment