User Prompt Dialog

Need quick input? This script launches a native browser input box asking the user a question, stores their answer in a variable, and displays it back to them.

Copy the Script

<script>
function askUser() {
    // 1. Prompt the user
    var name = prompt("Please enter your name:", "Harry Potter");
    
    // 2. Validate input
    if (name == null || name == "") {
        alert("User cancelled the prompt.");
    } else {
        alert("Hello " + name + "! How are you today?");
    }
}
</script>

Frequently Asked Questions

No. The input from a 'prompt()' box is plain text and visible on the screen. Do not use it for sensitive passwords or credit card data.

No. The prompt dialog is a browser-native interface and cannot be styled with CSS. For custom designs, you must build a custom HTML modal using forms.

The function returns 'null'. You should always check for 'null' in your code to handle cases where the user declines to answer.