• Resolved rierajf

    (@rierajf)


    Hello,

    Since I try your plugin, my jquery on change function doesn’t work anymore for input checkbox and I cannot understand why. Event is never catched anymore.

    <script>
    jQuery(document).ready(function($){
    
    // CALCULE LE TOTAL DES ACTIVITES SELECTIONNEES AU CHANGEMENT DES CHECKBOXES
    	$("input[name ^= 'chk_activite_']").on('change', function() {
    alert($(this).closest(".wpcf7-checkbox").attr('data-prix'));
                    var prix = Number($(this).closest(".wpcf7-checkbox").attr('data-prix'));
    
    		if (this.checked) {
    			var total_activite = Number($('#total_activite').val()) + 1;
    			var total = Number($('#total').val()) + prix;
    		} else {
    			var total_activite = Number($('#total_activite').val()) - 1;
    			var total = Number($('#total').val()) - prix;
    		}
    
    		$('#total_activite').val(total_activite);
    		$('#total').val(total);
    
    		if (total_activite < 2) {
    			document.getElementById('label_total').innerHTML = total_activite + ' activité sélectionnée pour un montant total de ' + total + ' €';
    		} else {
    			document.getElementById('label_total').innerHTML = total_activite + ' activités sélectionnées pour un montant total de ' + total + ' €';		
    		}
    		$('#submit_cb').val('Régler ' + total + ' € en CB sur le site HelloAsso et valider mon inscription');
    	});
    });
    </script>

    I don’t very well jquery, input checkbox fileds seems to be genereted the same with and without cf7-data-source plugin…

    Thanks in advance for your help 🙂

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @rierajf

    The issue is simple. If the checkboxes are generated dynamically from data source information, they do not exist when your code is evaluated. The correct is to capture the events in propagation:

    <script>
    jQuery(document).ready(function($){
        $(document).on('change', "input[name ^= 'chk_activite_']", 
        function() {
    
            // Your code Here
        });
    });
    </script>

    Best regards.

Viewing 1 replies (of 1 total)

The topic ‘jquery on change input checkbox doesn’t work when generated by cf7-data-source’ is closed to new replies.