Onclick href in a pivot table Campaings module

Hi, first sorry for my english.

I need your help with the following:

I have a href in a pivot table and i need to activate onclick event, I try the following:

    $('.tabDetailViewDL2').find('td').each(function(){
                    cantDestinatariosSeleccionados = $(this).html().replace(/[()]/g, '');
                    if($.isNumeric(cantDestinatariosSeleccionados))
                    {
                        cantDestinatarios = parseFloat(cantDestinatarios) + parseFloat(cantDestinatariosSeleccionados);
                    }
                    $("a[href='http://desa.agemacrm.co/index.php#']").click(function(){
                            alert('entrando a eliminar');
                            //http://desa.agemacrm.co/index.php?action=WizardNewsletter&module=Campaigns&return_module=Campaigns&return_action=WizardHome&return_id=a4df9744-9611-1db3-2f90-5f495bef068d&record=a4df9744-9611-1db3-2f90-5f495bef068d&direct_step=2#
                    });
                });  

By default the href calls an event onclick:

<a href="#" onclick="remove_target('trgt_added_1','1'); ">  
 <img src="themes/default/images/delete_inline.gif?v=PNW2aO2kEld0G1qNPEjvZg" width="12" height="12" 
   align="absmiddle" border="0" alt="Eliminar">
Quitar</a>`

I appreciate your help.

Best Regards

Can you explain a bit more? In which Module and View do you need to insert/override a URL ?

Thanks for reply

I am doing this customization in the campaigns module when selecting a target audience list when I create or modify a campaign; I’ll explain better, I’m developing an instruction to count the number of recipients to whom the campaign will be sent (target audience lists) so far so good; Now, it turns out that when I select the target audience lists, a pivot table is created with the recipients and a link appears to remove each one of the target audience lists if required (see attached image), which I need is to identify the event when you click that “remove” link so that you can create an instruction that will recount the number of recipients the campaign will be sent to.

What is happening with your code?

I’m no JQuery expert, but you should be able to check in the Dev console whether your changes to the HTML are working, and whether the click handler is getting correctly registered…

You can add JS code on Document ready that will check for any Changes to the Link Class.
Once you can trigger that, you can Check the HTML elements for the List and count the items remaining to show the Total.

Thanks guys

My problem is that when I click the “remove” link, I can’t get my custom code to run, here my code:

$("a[href='http://desa.agemacrm.co/index.php#']").click(function(){
                        alert('entrando a eliminar');
                        //http://desa.agemacrm.co/index.php?action=WizardNewsletter&module=Campaigns&return_module=Campaigns&return_action=WizardHome&return_id=a4df9744-9611-1db3-2f90-5f495bef068d&record=a4df9744-9611-1db3-2f90-5f495bef068d&direct_step=2#
                });

Maybe it is because the remove link is created dynamically and does not have an id, I need to know how to capture the event

I think you have to create the link, append it somewhere in the DOM, and then set the click handler. Not sure, though, I’m a beginner with Javascript and Jquery…

Thanks for you reply pgr

The link is created by default in the Campaign module, and I’m trying to change the onclick method for this href in the DOM, this is my complete code:

$(function ControlSendEmail() 
{
    $(document).ready(function(){
        $('.target-list-item').click(function(){
            var cantDestinatarios = 0;
            var cantDestinatariosSeleccionados = 0;
            
            $('.tabDetailViewDL2').find('td').each(function(){
                cantDestinatariosSeleccionados = $(this).html().replace(/[()]/g, '');
                if($.isNumeric(cantDestinatariosSeleccionados))
                {
                    cantDestinatarios = parseFloat(cantDestinatarios) + parseFloat(cantDestinatariosSeleccionados);
                }
                $("a[href='http://desa.agemacrm.co/index.php#']").click(function(){
                        alert('entrando a eliminar');
                        //http://desa.agemacrm.co/index.php?action=WizardNewsletter&module=Campaigns&return_module=Campaigns&return_action=WizardHome&return_id=a4df9744-9611-1db3-2f90-5f495bef068d&record=a4df9744-9611-1db3-2f90-5f495bef068d&direct_step=2#
                });
            });  
            //Recuperar cantidad de correos usados por cuenta
           if(idCuenta != '')
           {
                   $.ajax({
                   type: 'POST',
                   url: 'index.php?entryPoint=ControladorEmailEntryPoint',
                   data: {"account_id": idCuenta },
                   dataType: "json"
               })
               .done(function(response){
                   if(response.success)
                   {
                       if(cantDestinatarios > response.data.correos_disponibles)
                       {
                           //Remover clase de botones para evitar el envio de correo  wiz_submit_button wiz_next_button
                           $('#wiz_submit_button').hide();
                           $('#wiz_next_button').hide();
                           $('#wiz_submit_button').addClass("mensaje-excedio");
                           $('#wiz_next_button').addClass("mensaje-excedio");
                           $('.mensaje-excedio').before("Recuerde que la cantidad de correos que tiene disponibles: "+ response.data.correos_disponibles + " correos");
                       }else{
                           //Descontar correos disponibles y aumentar correos utilizados
                           $('#wiz_next_button').show();
                           $('#wiz_submit_button').show();
                       }
                   }
               })
               .fail(function() {
                   console.log( "Posting failed." );
               });
           }
        });
        
        $("a[href='http://desa.agemacrm.co/index.php#']").change(function(){
            alert('entrando a eliminar');
            //http://desa.agemacrm.co/index.php?action=WizardNewsletter&module=Campaigns&return_module=Campaigns&return_action=WizardHome&return_id=a4df9744-9611-1db3-2f90-5f495bef068d&record=a4df9744-9611-1db3-2f90-5f495bef068d&direct_step=2#
        });
    });
});

Is this returning an object?

$("a[href='http://desa.agemacrm.co/index.php#']")

In the debug yes, but the event onclick is null.

I suggest asking these question in some JQuery or Javascript forum, or simply on StackOverflow. This should be pretty simple for people who master JS (I certainly don’t)