How do I write a JavaScript to show a confirmation window, when you made changes in a form field and for some reason you leave the form? You know like a pop-up window or something informing the user that one or more form fields have been changed, do you want to save or cancel?
Confirmation when leaving a form
Started by MPD Psycho, May 23 2008 07:16 AM
5 replies to this topic
#1
Posted 23 May 2008 - 07:16 AM
|
|
|
#2
Posted 23 May 2008 - 07:20 AM
Use the alert() function to show a message (with just an OK button), and the confirm() function to show "OK" and "Cancel" buttons. confirm() and alert() both take one parameter - the text to show - and confirm() returns a boolean result reflecting the user's decision.
#3
Posted 23 May 2008 - 07:27 AM
I'm not a JavaScript expert. Can you show me a sample code or something?
#4
Posted 23 May 2008 - 07:33 AM
Neither am I! Sorry if I worded it badly. I think confirm() is the function to use. You pass in one parameter, the string, and it returns a boolean (true/false) value, depending on what the user clicked. For example:
Two messages are displayed - first to save, then to confirm exit. :)
var save = confirm('Going? Would you like to save?');
if (save)
{
//Do code to save here.
}
var exit = confirm('Are you SURE you want to exit?');
if (exit)
{
//Do code to exit.
}
else
{
//If necessary, do code to stop exiting.
}
Two messages are displayed - first to save, then to confirm exit. :)
#5
Posted 23 May 2008 - 07:46 AM
Are those the same window with different messages (which is what I'm looking for) or two separated windows?
#6
Posted 23 May 2008 - 07:51 AM
They are two different boxes that pop up one after another. Unfortunately, you cannot easily display more than one set of OK and Cancel buttons - you need one per message, so one per box. However, you could create a custom dialog box as an HTML page, then use window.open() to display it.


Sign In
Create Account


Back to top









