Prompt - Cancel/OK Result?

C

Chris Ashley

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
 
B

Bart Van der Donck

Chris said:
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.');
}
 
R

Randy Webb

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




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.
 
B

Bart Van der Donck

Randy said:
Bart Van der Donck said the following on 1/13/2006 11:28 AM:

And if user clicked the X the value is null.

And if user pressed Escape the value is null.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top