Question

I have the following code which is added to a delete button on my Joomla site:

$doTask = "if (document.adminForm.boxchecked.value==0){
    alert('$message');
}                                  
 else { 
      Joomla.submitbutton('$task')
 }";

$i18n_text = JText::_($text);
$class = JButton::fetchIconClass($name);


$html = "<a href=\"javascript: void();\" onclick=\"$doTask\" class=\"toolbar\">\n";
$html .= "<span class=\"$class\">\n";
$html .= "</span>\n";
$html .= "$i18n_text\n";
$html .= "</a>\n";

The button works fine and I can delete records. The problem I have is that before a record is deleted, I would like to show a popup that asks the user if they are sure they want to delete. There should be an 'confirm' button and a 'cancel' button. If the confirm button is clicked, the records are deleted, if the cancel button is clicked no deletion occurs.

Im not really sure how get this functionality to work.

Was it helpful?

Solution

Replace your else part with this code:

else { 
   if(confirm('Are you sure you want to delete ?'))      
      Joomla.submitbutton('$task');
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top