I have this function here that is run with the Onclick attribute for a html button. How do I insert a confirmation box before the fuction returns true. When the user click "OK" on the confirmation box the script needs to return true. It is a delete confirmation. Thanks! function validate() { if(document.form.user.value=="") { alert("Please Select the Recipient(s)"); return false; } return true; }
Try: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <script type="text/javascript"> var answer = confirm ("Are you sure you want to delete your message?") if (answer) { alert ("Your message has been deleted.") } else { alert ("Canceled!.") } </script> </body> </html> Code (markup):