Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding JS To Codeigniter Links - Simple OnClick

I am trying to write a simple Javascript snippet into a Codeigniter link. I am using the link to delete posts where required in my dashboard. I dont know anything about JS although am trying to learn it.

Code

$js = 'onClick = "alert("Are you sure")"';

$this->table->set_heading('Date', 'Title', 'Delete', 'Update');

foreach($records as $row){
$row->title = ucwords($row->title);
$this->table->add_row($row->date,
$row->title = ucwords($row->title),    
anchor("main/delete/$row->id", $row->id, $js), //this is the link in question
anchor("main/fill_form/$row->id", $row->id)
);
}
$table = $this->table->generate();
echo $table;

My question is how to write the JS for the link ($js). I would like to use a confirm statement, (yes or no). I am totally lost with JS to prevent accidental deletions

Thank you

like image 809
Brad Avatar asked Dec 13 '25 07:12

Brad


1 Answers

Here's how you might do it with the CodeIgniter anchor function :

echo anchor('delete/something', 'Delete', array('onClick' => "return confirm('Are you sure you want to delete?')"));

This displays a confirmation box when the link is clicked. If the user confirms then the link is followed. If the user cancels then no action is taken.

like image 89
Stephen Curran Avatar answered Dec 14 '25 20:12

Stephen Curran