prompt (true and false, not work)!

5.1k views Asked by At

I have two option in prompt, acept and cancel, here is ok, but when I do cancel in prompt, this generate a list of anyway, why not function?

  add.onclick = function(){
   if(true) {
    var itemText = prompt('Create a Memo');
   }else {
    return false;
  }
2

There are 2 answers

0
silentw On BEST ANSWER
var question = prompt('Create a memo');
if(question) {
    alert('true - ' + question);
} else {
    alert('false - ' + question);
}

DEMO

Another example:

var question = prompt('Create a memo');
if(question) {
    document.getElementById('text').innerHTML = 'I answered ' + question;
} else {
    document.getElementById('text').innerHTML = 'I canceled';
}

DEMO 2

0
SP User2017 On

to get true or false in variable, use confirm statement