How can I make cancel button in javascript prompt box to do nothing like the cancel button on confirmation box instead of sending “null” values?
Or is it possible to remove the cancel button from the prompt box so there is only “ok” button left?
This is what I have tried but it still sends the null to value to my PHP file.
function AskQuestion(data)
{
var id = getUrlVars()["id"];
console.log(data);
if(data.key[0].status == "ok") {
var reply = prompt(data.key[0].REPLY, "");
var index = data.key[0].IND;
if(reply != "" && reply !== null) {
//do nothing
}else{
jQuery.ajax({ type: "POST",
url: serviceURL + "message.php",
data: 'id='+id+'&arvo='+reply+'&index='+index,
cache: false,
success: AskQuestion});
}
} else {
window.location = "page.html"
}
}
You’ve got your test on the return value the wrong way around. As it is you
// do nothingwhen the user enters text, and callajaxwhen they don’t. Changeto