views:

54

answers:

1

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

+1  A: 

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.

Stephen Curran
Thank you ever so much. I should have learned JS a long time ago. You are appreciated
Brad
Great :-) Glad to help.
Stephen Curran