By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,756 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

Prompt - Cancel/OK Result?

P: n/a
Hi there,

Does the prompt method return a value indicating which button the user
pressed (OK or Cancel) ? If so, how can I access this as it just seems
to return the text the user entered?

Thanks,

Chris

Jan 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Chris Ashley wrote:
Does the prompt method return a value indicating which button
the user pressed (OK or Cancel) ?
If so, how can I access this as it just seems > to return the text
the user entered?


If user clicked OK, the value is not null.
If user clicked Cancel, the value is null.

var p;
p = prompt('What is your age ?','');

if (p == null) {
alert('Cancel was clicked.');
}
else {
alert('OK was clicked.');
}

--
Bart

Jan 13 '06 #2

P: n/a
Bart Van der Donck said the following on 1/13/2006 11:28 AM:
Chris Ashley wrote:

Does the prompt method return a value indicating which button
the user pressed (OK or Cancel) ?
If so, how can I access this as it just seems > to return the text
the user entered?

If user clicked OK, the value is not null.
If user clicked Cancel, the value is null.


And if user clicked the X the value is null.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 13 '06 #3

P: n/a
Randy Webb wrote:
Bart Van der Donck said the following on 1/13/2006 11:28 AM:
If user clicked OK, the value is not null.
If user clicked Cancel, the value is null.


And if user clicked the X the value is null.


And if user pressed Escape the value is null.

--
Bart

Jan 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.