Skip to main content

Javascript: alert box, prompt box and confirm box

Alert box:

It displays an alert dialog with a text message and OK button
Example:
Code:
<html>
<head>
<script type=”text/javascript”>
function showAlert()
{
    alert(“Hey!! This is an alert box”);
}
</script>
</head>
<body>
<input type=”button” onClick=”showAlert()” value=”Show” />
</body>
</html>
In above example, only the text Hey!! This is an alert box appears.

Prompt Box:

Prompt is used to allow a user to enter something, and do something with that value.
Code:
<html>
<head>
<script type=”text/javascript”>
function showPrompt()
{
    var name=prompt(“Please enter your name”, “Awaken Nepal”);
    if(name!=null && name!=”")
    {
    document.write(“Hello”+name+”! How are you?”);
    }
}
</script>
</head>
<body>
<input type=”button” onClick=”showPrompt()” value=”Show” />
</body>
</html>
In above example, the alert box with user input field appears to take an input from the user and then do the necessary process.

Confirm Box:

Confirm is used to confirm a user about certain action, and decide between two choices depending on what the user chooses.
Code:
<html>
<head>
<script type=”text/javascript”>
function showConfirm()
{
    if(confirm(“Are you sure you want to delete this record?”))
    {
        alert(“Okay deleted”);
    }
    else
    {
        alert(“Not deleted”);
    }
}
</script>
</head>
<body>
<input type=”button” onClick=”showConfirm()” value=”Show” />
</body>
</html>
In above example, user can choose whether or not an action to be  performed. A confirm box will pop up much like an alert box, but will allow the viewer to press an “OK” or “Cancel” button.

Comments

Popular posts from this blog

CSS List

CSS allows you to customize the lists that can be made with HTML  to the extent that even images can be used as bullet points for unordered lists. CSS List Style Type If you want to use something different from the default numbering of ordered lists, or the bullets/discs of unordered lists, then all you have to do is choose a different style for your lists. CSS allows you to select from a wide variety of different list item shapes. Unordered list styles: square, circle, disc (default), and none Ordered list styles: upper-alpha, lower-alpha, upper-roman, lower-roman, decimal (default), and none Code:

Accessible Forms

Forms aren't the easiest of things to use for people with disabilities. Navigating around a page with written content is one thing, hopping between form fields and inputting information is another. Because of this, it is a good idea to add a number of elements to the form. Labels Each form field should have its own label. The label tag sorts this out, with a for attribute that associates it to a form element:

Join in MySQL

Join clause is used to combine rows from two or more tables depending upon common field between them. There are different kinds of Joins. The most common and useful Join is Inner Join. Inner Join: It will return all rows from multiple tables where the condition is met.