Hi Guys  , 
          i started experimenting a little bit with javascript . I want a javascript dialog that ask user to delete a file.Buttons should be yes or no.The javascript should load as soon as page load **No button is used**.
Can you please post a sample code for it 
You can use a simple hello world html page 
For example when page load a javascript popup appears and ask user whether to search.If user clicks yes , then google(dot)com opens , nothing is done 

Please try to implement it with php as for my application , if user click yes some php code will be executed , else nothing is done.

Thanks for helping out guys

Sorry for code tag but i keep getting

The code snippet in your post is formatted incorrectly. Please use the Code button in the editor toolbar when posting whitespace-sensitive text or curly braces.

4 Years
Discussion Span
Last Post by Khav

Thanks for the link dude
But how can confirm this by php
for e.g when i use this code

<!doctype html>

<html lang="en">
    <meta charset="utf-8" />
    <title>jQuery UI Dialog - Modal confirmation</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script src="/resources/demos/external/jquery.bgiframe-2.1.2.js"></script>
    <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    $(function() {
        $( "#dialog-confirm" ).dialog({
            resizable: false,
            modal: true,
            buttons: {
                "Delete all items": function() {
                    $( this ).dialog( "close" );
                Cancel: function() {
                    $( this ).dialog( "close" );

<div id="dialog-confirm" title="Empty the recycle bin?">
    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>

Set the modal option to true, and specify primary and secondary user actions with the buttons option.

Sorry for asking this but i am beginner in javascript
Can anyone should be how to set commands for the buttons in php
show me a sample TO SET THE USER ACTION
i am expecting something of this structure

If confirm = true then 
//Do something 
//Do nothing 

PHP is not like Javascript, it is parsed by the server before the script is loaded in the browser. Once the page is loaded, PHP is finished until the next script load. If you want PHP to do anything in response to user input/action, you need to collect data using forms and reload the page (submit the form) with the PHP code ready to respond. Another option is to use Javascript to send a HTTP request to a PHP page mimicing the behaviour of a form being submitted (in the background), and again using Javascript to deal with the PHP response.


Dear Khav,

Assume that you have a delete icon with the anchor tag
<a href='?del_id=<?php echo $id; ?>'>Delete this</a>
Where del_id refers the post id which you want to delete.

<a href='?del_id=<?php echo $id; ?>' onclick='return confirm("Are you sure want to delete this ?");'>Delete this</a>

That will open a confirm box with the text "Are you sure want to delete this ?"
If you click YES it will load the same page. At the top of the page you write the code for deletion.

        // Code for deleting the $_GET['del_id'];

If you click NO it will do nothing.

Edited by rayidi

Votes + Comments
Gr8 post and thanks for help

Thanks so much krish
Your code snippet is nearly perfect for my site
However i don't want to use any button
Like when user navigate to
http://mysite.com/delete/file.exe , a confirm box with the text "Are you sure want to delete this ?" should appear
Thanks again

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.