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
    An Interview with Eric Meyer

    Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it? At first blush, it was the simplicity of it as compared to the table-and-spacer...

  • By
    Page Visibility API

    One event that's always been lacking within the document is a signal for when the user is looking at a given tab, or another tab. When does the user switch off our site to look at something else? When do they come back?

Incredible Demos

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!