PGDEL/DECP03/Unit3/20

From WikiEducator
< PGDEL‎ | DECP03‎ | Unit3
Jump to: navigation, search



Unit 3.3 Web application development tools & Technologies
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>

Road Works.svg Work in progress, expect frequent changes. Help and feedback is welcome. See discussion page. Road Works.svg