Create a JavaScript Confirmation Box

By  on  

Javascript confirmation boxes aren't used nearly as often as they used to be, mostly due to more advanced usages of JavaScript and modal boxes, but they are still helpful. Whenever I create administrative functionality for my customers, I always use a JavaScript confirmation box before executing any permanent action -- an example would be when a customer tries to delete a file.

The Code / Example

Delete File

The confirm method returns the true/false result of the confirm box.

Recent Features

  • By
    Designing for Simplicity

    Before we get started, it's worth me spending a brief moment introducing myself to you. My name is Mark (or @integralist if Twitter happens to be your communication tool of choice) and I currently work for BBC News in London England as a principal engineer/tech...

  • By
    Welcome to My New Office

    My first professional web development was at a small print shop where I sat in a windowless cubical all day. I suffered that boxed in environment for almost five years before I was able to find a remote job where I worked from home. The first...

Incredible Demos

  • By
    Degradable SELECT onChange

    Whenever I go to Google Analytics I notice a slight flicker in the dropdown list area. I see a button appear for the shortest amount of time and the poof! Gone. What that tells me is that Google is making their site function...

  • By
    CSS Tooltips

    We all know that you can make shapes with CSS and a single HTML element, as I've covered in my CSS Triangles and CSS Circles posts.  Triangles and circles are fairly simply though, so as CSS advances, we need to stretch the boundaries...

Discussion

  1. it is really cool!

  2. netmastan

    doesn’t work on FF. If you hit cancel still goes to the link

  3. clikcspeed

    You rock! This is great, was just looking for a way to pass PHP variable to javascript but with this tutorial I don’t have to complicate things, the whole process becomes less cumbersome… Really great stuff man!!!

  4. toinkees

    this helped me have an idea… thanks guys!!!..

  5. PHPSUCK

    var c=confirm(“Are u sure?”);
    if(c== false)
    {return false;}
    else
    return true;

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!