Persistent prompt modal
suggest changeprompt and alert are browser dialogs, and they block the page. Cancel makes prompt return null. Submitting the box with nothing typed returns "".
To prevent empty values and make it more persistent:
<h2>Welcome <span id="name"></span>!</h2>
<script>
// Persistent Prompt modal
var userName;
while(!userName) {
userName = prompt("Enter your name", "");
if(!userName) {
alert("Please, we need your name!");
} else {
document.getElementById("name").textContent = userName;
}
}
</script>
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents