Php – Questions regarding PHP and mootools

mootoolsPHPselection

My question is how to pull the username into the confirmation popup… would I have to change the way my php is generating the list of users or would it need some mootools coding to select the parent and then the username… if so how could I achieve that?

I have my PHP code using codeigniter to generate the following kinda things which is basically listing a username and a link to delete the user.

<div class='item'> 
<a href="http://localhost/nstrust/index.php/admin/users/delete/9" class="delete">Delete</a> <a href="http://localhost/nstrust/index.php/admin/users/view/9" class="view">Jamalia</a>
</div> 
<div class='item'> 
<a href="http://localhost/nstrust/index.php/admin/users/delete/13" class="delete">Delete</a> <a href="http://localhost/nstrust/index.php/admin/users/view/13" class="view">Timothy</a>
</div> 

I have the following mootools code to pop up and confirmation to see if the user really want to delete the user

 window.addEvent('domready', function()
 {
    $$('a.delete').addEvent('click', function(event)
    {
        if (!confirm("Are you sure you want to remove this user?"))
        {
            event.stop();
        }
    });
 });

Best Answer

The following will work nicely on your markup:

$$('a.delete').addEvent('click', function(event) {
  var username = $(event.target).getNext().get('text'); //The username is in the next tag.
  if (!confirm("Are you sure you want to remove " + username + "?")) {
    event.stop();
  }
});

Since the next link holds the user name, you can simply traverse the DOM to it and get the text value.