Search code examples
javascriptjqueryprompt

Javascript prompt box without the cancel button?


Is there a way to create a input prompt box that doesn't have the cancel button, or doesn't allow the user to close the prompt until some value is entered?


Solution

  • Put your promt inside a while loop and continue asking for input until user gives any.

    do{
        input = prompt("Give input");
    }while(input == null || input == "" );
    
    console.log(input);
    

    jsFiddle

    [Note : It's a way to fulfill your requirement that I won't suggest as it may annoy user. You can go with regular expression if you want user to complete your form.]