Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirm box in CodeIgniter anchor link to delete record

I am using the following code to delete a record from a database. But I am facing a problem: when I click on "cancel" in the confirm box then it deletes the record. If I click cancel it returns false but how does it delete the record?

What am doing wrong?

Javascript code:

function ConfirmDialog() {
  var x=confirm("Are you sure to delete record?")
  if (x) {
    return true;
  } else {
    return false;
  }
}

PHP code in view:

<?php
  echo anchor('user/deleteuser/'.$row->id, 'Delete', array('class'=>'delete', 'onclick'=>"return ConfirmDialog();"));
?>
like image 234
Kango Avatar asked Mar 06 '13 06:03

Kango


1 Answers

Everything in one line

<?=anchor("user/deleteuser/".$row->id,"Delete",array('onclick' => "return confirm('Do you want delete this record')"))?>
like image 164
Jamshid Hashimi Avatar answered Sep 20 '22 19:09

Jamshid Hashimi