-1

I want to get an answer from users in my website using javascript alert()

  1. User Clicks button and Alert pops up
  2. User Clicks on Yes or No
Shiny
  • 4,945
  • 3
  • 17
  • 33
kosice
  • 15
  • 3

2 Answers2

3

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!";
}

enter image description here

or prompt() if you want the user to type something

var userInput = prompt("Please enter your name");
Shiny
  • 4,945
  • 3
  • 17
  • 33
ButchMonkey
  • 1,873
  • 18
  • 30
0

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.

SrHadeSito
  • 44
  • 7
  • "True" or "False " is not "the text to be displayed" it is the return value https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm – ButchMonkey Jan 18 '20 at 00:27