The prompt() is used for displays a dialog for user to input some text.
If the user clicks "OK", the input value is returned. If the user clicks "cancel", null is returned. If the user clicks OK without entering any text, an empty string is returned.
Dialog boxes are modal windows; they prevent the user from accessing the rest of the program's interface until the dialog box is closed. For this reason, you should not overuse any function that creates a dialog box
Demo
If the user clicks "OK", the input value is returned. If the user clicks "cancel", null is returned. If the user clicks OK without entering any text, an empty string is returned.
Dialog boxes are modal windows; they prevent the user from accessing the rest of the program's interface until the dialog box is closed. For this reason, you should not overuse any function that creates a dialog box
var Name = prompt("Please enter your name");Final code and demo is here
if (Name !== null)
{
if (Name !== "")
{
//If the user clicks OK with text
}
else
{
//If the user clicks OK without entering any text
}
}
Demo
No comments:
Post a Comment