I want to get an answer from users in my website using javascript alert()
- User Clicks button and Alert pops up
- User Clicks on Yes or No
I want to get an answer from users in my website using javascript alert()
Use confirm()
to have a yes / no (cancel) option.
var txt;
var r = confirm("Press a button!");
if (r === true) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
or prompt()
if you want the user to type something
var userInput = prompt("Please enter your name");
Like the JavaScript Alert(), there's a similar one called confirm().
For instance,
confirm("Pick true or false");
That "Pick True or False" is the text to be displayed, and then you have to pick between confirm or cancel. Also, you can make some if statements, based on the confirm pick.