3

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 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you ever so much. I should have learned JS a long time ago. You are appreciated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.