JavaScript Dialog Box
A JavaScript dialog box is predefined function which is used to perform different task.
Some functions are used in JavaScript Dialog box.
Function | Description |
---|---|
alert() | To give alert message to user |
prompt() | To input value from used |
Confirm() | To get confirmation from user before executing |
Alert()
Alert() function in JavaScript is used to give an alert message to the user.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<!DOCTYPE html> <html> <body> <script> function alertmsg() { alert("Alert function call"); } </script> </body> <form> <input type="button" value="Click Me" onclick="alertmsg()"/> </form> </html> |
prompt()
Prompt function in JavaScript is used to get input from user.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<!DOCTYPE html> <html> <body> <script> function alertmsg() { a=prompt("Enter your name:"); alert(a); } </script> </body> <form> <input type="button" value="Click Me" onclick="alertmsg()"/> </form> </html> |
Confirm()
Confirm function in JavaScript is used to get confirmation from user before executing some task.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<!DOCTYPE html> <html> <body> <script> function alertmsg() { a=prompt("Enter your name:"); confirm(a); } </script> </body> <form> <input type="button" value="Click Me" onclick="alertmsg()"/> </form> </html> |