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
    Responsive Images: The Ultimate Guide

    Chances are that any Web designers using our Ghostlab browser testing app, which allows seamless testing across all devices simultaneously, will have worked with responsive design in some shape or form. And as today's websites and devices become ever more varied, a plethora of responsive images...

  • By
    From Webcam to Animated GIF: the Secret Behind chat.meatspac.es!

    My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...

Incredible Demos

  • By
    Fix Anchor URLs Using MooTools 1.2

    The administrative control panel I build for my customers features FCKEditor, a powerful WYSIWYG editor that allows the customer to add links, bold text, create ordered lists, and so on. I provide training and documentation to the customers but many times they simply forget to...

  • By
    pointer Media Query

    As more devices emerge and differences in device interaction are implemented, the more important good CSS code will become.  In order to write good CSS, we need some indicator about device capabilities.  We've used CSS media queries thus far, with checks for max-width and pixel ratios.

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!