jeudi 1 décembre 2016

Running javascript only if php condition is met

How do you run javascript if only a php condition is met? I am trying to show a pop-up only if $page_count is <= 1. The php is fine and runs correctly as I have tested it with simple echos, it is only when I try to negate the javascript from running if the $page_count is over 2 that this still runs.

Is there a common method to go about this?

if ($page_count <= 1) {
    $setup_popup =
    '<div id="status-popup">
        <div id="status-popup-container" class="total-center">
            <a class="popup-close" data-popup-close="popup-1" href="#">Close</a>
        </div>
    </div>'
    ;
}
else {
    $setup_popup = NULL;
}

Javascript

$('#status-popup').fadeIn(350);

$('[data-popup-close]').on('click', function(e)  {
    var targeted_popup_class = jQuery(this).attr('data-popup-close');
    $('#status-popup').fadeOut(350);
    $('body').css('overflow', 'auto');
     e.preventDefault();
});

Aucun commentaire:

Enregistrer un commentaire