supportsp supportsp - 10 months ago 40
Javascript Question

prompt (true and false, not work)!

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

Answer Source
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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download