Confirmation Alert Box using JavaScript

In this article, we are going to create Confirmation Alert Box using JavaScript. You can use this simple script source code to give any confirmation to the user or the admin whether delete, accept, add, view, or etc. This simple article usually used for deleting or confirming information to your systems or websites. This is a simple source code. Enjoy coding.

Let's Begin:

Do this:
  • Creating Markup
  • Creating our Script
First, we are going to create our simple Markup. Kindly copy and paste this HTML source code to your BODY tag of your page.
  1. <a id="<?php echo $id;?>" class="delete_member" style="margin-left:15px;"><i class="icon-trash"></i>
  2.  Delete
  3. </a>   
Second, we are going to construct our simple script to execute the Confirm Alert Box. Copy and paste it below your Markup source code.
  1. <script type="text/javascript">
  2.        $(document).ready( function() {
  3.            $('.delete_member').click( function() {
  4.                var id = $(this).attr("id");
  5.                if(confirm("Are you sure you want to delete this Member?")){
  6.                    $.ajax({
  7.                        type: "POST",
  8.                        url: "delete_member.php",
  9.                        data: ({id: id}),
  10.                        cache: false,
  11.                        success: function(html){
  12.                            $(".del"+id).fadeOut('slow');
  13.                        }
  14.                    });
  15.                }else{
  16.                    return false;}
  17.            });                         
  18.        });
  19. </script>
And, this is a delete_member.php page.
  1. <?php
  2. include('dbcon.php');
  3.  
  4. $id=$_POST['id'];
  5.  
  6. mysql_query("delete from reg_member where member_id='$id'") or die(mysql_error());
  7.  
  8. ?>
Hope that this simple article that I created may help you to your future projects. Also, for the beginners who want to learn basic of coding in JavaScript. Result If you are interested in programming, we have an example of programs that may help you even just in small ways. If you want more tutorials, you can visit our website, click here Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment