admin管理员组

文章数量:1400174

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

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

Share Improve this question asked Aug 13, 2010 at 15:17 BradBrad 1,6911 gold badge27 silver badges38 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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.

本文标签: phpAdding JS To Codeigniter LinksSimple OnClickStack Overflow