Reputation: 9866
I have this simple function
function Login()
{
var x=prompt("Please enter your name","");
var xmlhttp;
if (window.XMLHttpRequest)
{// Използваните браузъри
xmlhttp=new XMLHttpRequest();
}
else
{// Кой ли ползва тези версии..
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","login.php?u="+x,true);
xmlhttp.send();
}
The problem is when the user decide to exit the prompt box by clicking ESC.Can someone explain to me what exactly happen with the variable x in this case.I get to the conclusion that it get assignied with the value 'null' and by null I mean a string, because when I check with
If(!is_null($u))
my script doesn't work, but if I replace this with
If($u!='null')
then everything works just fine, so could someone explain me what in fact is happening with the prompt box value when you exit it with pressin ESC?
Upvotes: 0
Views: 994
Reputation: 195992
It returns as if you had clicked cancel.
It is null
not as a string ..
alert( prompt('') === null );
will alert true
if you press Esc or cancel button
Upvotes: 0
Reputation: 1074266
x
will receive the null
value when the user cancels the prompt, so:
var x=prompt("Please enter your name","");
if (x === null) {
// User canceled
}
Upvotes: 1