WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript Popup Boxes


JavaScript has three sort of popup boxes: Alert box, Confirm box, and Prompt box.


Alert Box

An ready box is frequently utilized in the event that you need to ensure data comes through to the user.

When an alarm put away pops, the client should click "OK" to continue.

Syntax

window.alert("sometext");

The window.alert() technique can be composed without the window prefix.

Example

alert("I am a caution box!");
Try it yourself »

Confirm Box

A affirm box is frequently utilized in the event that you need the client to confirm or acknowledge something.

When an affirm take care of pops, the client should click either "OK" or "Cancel" to continue.

If the client clicks "OK", the container returns genuine. In the event that the client clicks "Cancel", the crate returns false.

Syntax

window.confirm("sometext");

The window.confirm() technique can be composed without the window prefix.

Example

var r = confirm("Press a button");
on the off chance that (r == genuine) {
    x = "You squeezed OK!";
} else {
    x = "You squeezed Cancel!";
}
Try it yourself »

Prompt Box

A brief box is regularly utilized on the off chance that you need the client to include an incentive before entering a page.

When a brief box springs up, the client should click either "OK" or "Cancel" to continue in the wake of entering an info esteem.

If the client clicks "OK" the crate restores the information esteem. On the off chance that the client clicks "Cancel" the case returns null.

Syntax

window.prompt("sometext","defaultText");

The window.prompt() strategy can be composed without the window prefix.

Example

var individual = prompt("Please enter your name", "Harry Potter");
if (individual != invalid) {
    document.getElementById("demo").innerHTML =
    "Hello " + individual + "! How are you today?";
}
Try it yourself »

Line Breaks

To show line breaks inside a popup box, utilize an oblique punctuation line pursued by the character n.

Example

alert("Hello\nHow are you?");
Try it yourself »