Unit3.3-JS-DialogBox

From WikiEducator
Jump to: navigation, search
Uou-logo-100px.png
Home  |  About UOU  |  About CEMCA  |  Contact Us    

Unit 3.3 Web application development tools & Technologies


3.3.5 JavaScript
  3.3.5.1 Data Types
  3.3.5.2 Variables
  3.3.5.3 Operators
  3.3.5.4 Conditional statement
  3.3.5.5 Dialog Boxes
  3.3.5.6 Functions


3.3.5.5 Dialog Boxes

JavaScript provides the capability to accept user inputs or display message to the users by using dialog boxes. Dialog boxes appear in a separate window.There are three types of the dialog boxes provided by JavaScript:

Dialog Box
Syntax
Example

Alert Dialog Box


This is a simple way to display small message to a browser’s dow.

alert(“<Message>”)   
<HTML>
<HEAD>
<TITLE> Demonstrating Alert Dialog Box</TITLE>
</HEAD>
<BODY">
<SCRIPT type="text/javascript" >
alert("Hello there");
</SCRIPT>
</BODY>

Prompt Dialog Box

</HTML>Prompt Dialog BoxThe prompt dialog box allows interaction; it can used to customize any web page based on user input.

prompt(“<Message>”,”<Value>”)
<HTML>
<HEAD>
<TITLE> Demonstrating promptDialog Box </TITLE>
</HEAD>
<BODY">
<SCRIPT type="text/javascript" >
var name = prompt("Enter your Name","Your Name");
document.write(" Welcome : "+name);</SCRIPT>
</BODY>
</HTML>

Confirm Dialog Box:


The value entered into the prompt dialog box can be stored in a variable to use further.Confirm Dialog BoxThis is used to confirm user action. The confirm dialog box halts the program execution until user action takes place. User can either click ok or cancel, clicking on ok button causes true to be passes and cancel pass false to the program.

confirm(“<Message>”);
<HTML>
<HEAD>
<TITLE> Demonstrating Confirm Dialog Box </TITLE>
</HEAD>
<BODY">
<SCRIPT type="text/javascript" >
var value=confirm("Sure to exit");
if(value)
document.write(" Exit ");
else
document.write(" Continue ");
</SCRIPT>
</BODY>
</HTML>

                                                                                                 Next

Suggested Reading
  • Web Applications


 Suggested Videos
  • Video 01 Title
  • Video 02 Title
  • Video 03 Title