Persistent prompt modal

suggest change

prompt 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>

jsFiddle demo

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents