Cancel button on the input box function

10 pts.
Tags:
NULL values
Strings
In the input box operation, the cancel button does not actually cancel the operation, what am I doing wrong? Instead it returns a null value and continues with the rest of the string of code
ASKED: July 10, 2008  1:59 PM
UPDATED: July 10, 2008  8:05 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

If you’re talking about the Javascript window.prompt function, you want to test the return value:

<pre>
var x = window.prompt(“What is your name?”, “Enter your name here”);
if (x) { // test for x as null or undefined
if (/\S+/.test(x)) { // test that x is not an empty string
if (x != “Enter your name here”) { // test that x is not the default value
// do something
}
}
}
</pre>

It depends on how much validation you want from the prompt return value.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following