User Input Prompt

The quick and dirty way to get data. This script utilizes the built-in browser dialog box to request information from the user without creating a form.

Copy the Script

<script>
function getName() {
    var name = prompt("Please enter your name:", "Guest");
    
    if (name != null && name != "") {
        document.getElementById("output").innerHTML = "Hello " + name;
    } else {
        document.getElementById("output").innerHTML = "User cancelled the prompt.";
    }
}
</script>

<button onclick="getName()">Ask Name</button>
<p id="output"></p>

Frequently Asked Questions

No, but it is discouraged for modern UX because it pauses the entire browser thread (blocking) and cannot be styled. Custom modal dialogs (using HTML/CSS) are preferred.

No. The standard `prompt()` box always displays plain text. You cannot mask characters as asterisks. For passwords, you must build a custom HTML modal.

The function returns `null`. You should always check `if (result !== null)` before using the data.