0

Hi all.I found this code on a forum to confirm that the user wants to delete the record from database and that the link has not pressed accidently.But it is not deleting the record even after pressing ok.This is may be because the id is not passed properly. Can anyone tell why?Do I need to modify the javascript function?Here is my code:

function confirmation() {
	var answer = confirm("Delete Record?")
	if (!answer){
		
		window.location = "by_hand.php";
		}
         else
         {
               window.location = "delete.php?delete=$id&action=deleteemployee";
          }
}
<a href=# onclick='confirmation()'><img src='images/delete.png' alt='Delete' title='Delete' class='pngfix'></a>
3
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by anita_86
0

Hi,

for what I can see, you don't have the id value, you just have the string '$id'.

This is all of your code?

0

Actually im displaying total records from the database and when user clicks on certain record, I want a confirmation box that user havent clicked the button accidentally.So $id is the id of that particular record.And through href the

delete.php?delete=$id&action=deleteemployee

link works fine.Just dont know how to do it through js.If I alert $id, it displays just $id and not the value.

0

You'll need to output your rows a little differently through PHP, add the id in the confirmation function:

<a href=# onclick='confirmation(1)'><img src='images/delete.png' alt='Delete' title='Delete' class='pngfix'></a>

And then use this javascript:

function confirmation(id) {
  var answer = confirm("Delete Record?")
  if (!answer) {
    window.location = "by_hand.php";
  }
  else
  {
    window.location = "delete.php?delete=" + id + "&action=deleteemployee";
  }
}
1

Thanks for your valuable reply pritaeas.It was very helpful and it solved the issue.
My new code is

<script type="text/javascript">
function deleteRecord(recID){
                var ans = window.confirm('Delete Record?');
                if(ans == true){
				                    window.location.href='delete.php?delete='+recID+'&action=deleteemployee';
                 }
            }
     </script>
$id=$row['eng_id'];
 echo '<a href="" onclick="deleteRecord('."'" . $id . "'" .');return false;"><img src="images/delete.png" alt="Delete" title="Delete" class="pngfix"></a>';
Votes + Comments
Thanks for sharing.
This question has already been answered. 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.