Welcome Guest, Not a member yet? Register   Sign In
delete confirm message in anchor
#1

[eluser]gayathri[/eluser]
Hi,

I am new to code igniter,i am using anchor, while deleting i want to display the "are you sure you want to delete" , so please tell me the code for anchor,

my present code is

anchor('sample/delete_users/'.$row->id, 'Delete');

where to add the confirm message? , please let me know, thanks
#2

[eluser]mr.green[/eluser]
Code:
<a href="[removed]if(confirm('Are you sure ?')) location.href=''">Delete</a>
#3

[eluser]xwero[/eluser]
Code:
anchor(’sample/delete_users/’.$row->id, ‘Delete’,array('class'=>'confirm'));
jquery (javascript code)
Code:
$(function(){
  $('.confirm').click(function(){
    var r=confirm("Are you sure")
  if (r==false)
    {
    return false;
    }
  });
});
#4

[eluser]gayathri[/eluser]
Hi,

Thanks for your reply, but its not working for me, i don't know where to place this javascript code, what i did is, in view


$(function(){
$('.confirm').click(function(){
var r=confirm("Are you sure")
if (r==false)
{
return false;
}
});
});


anchor(’sample/delete_users/’.$row->id, ‘Delete’,array('class'=>'confirm'));


but no reaction at all. please help me
#5

[eluser]Michael Wales[/eluser]
Are you loading the jQuery library? If so, then you I would place that function in another javascript file and load it immediately after loading the jQuery library. Your anchor tag looks to be correct.
#6

[eluser]gayathri[/eluser]
no, i didn't load jquery, so is there any other way to do this?
#7

[eluser]Michael Wales[/eluser]
Use this code sample:
Code:
<a href="[removed]if(confirm('Are you sure ?')) location.href=''">Delete</a>

Honestly, I would take the jQuery route - it's less obtrusive and will degredate gracefully if the user doesn't have Javascript enabled. Getting jQuery running is very easy just search these forums and check out the jQuery website.
#8

[eluser]xwero[/eluser]
Or any other javascript library that allows unobtrusive code, to keep the peace Wink

But it's not the only benefit. Keeping the javascript generated sentences, but also html code, centralized your code is easier to maintain and extend. I'm thinking about multilanguage, styled popups, and other goodies like the confirmer plugin
#9

[eluser]xwero[/eluser]
but if you insist on using inline javascript i think this snippet is better
Code:
&lt;a href="http://codeigniter.com" onclick="javascriptt:if(!confirm('Are you sure ?')) return false"&gt;Delete</a>




Theme © iAndrew 2016 - Forum software by © MyBB