Home IF condition multiple parameters not working
Reply: 0

IF condition multiple parameters not working

user1962
1#
user1962 Published in May 28, 2018, 8:18 am

I have a plugin where a modal pops up during a particular time as per defined in the backend. If the user is browsing through the page and the modal is suppose to display say at 4:33pm then it will pop up. This is the basic concept.

This is my code :

<script type="text/javascript">
        day = [];
        timeu = [];
        msg = [];
        var time_zone = '<?php echo $text[0]->time_zone;?>';

    </script>
    <?php
    foreach ($text as $post) {
    ?>
        <script type="text/javascript">
            day.push('<?php echo date("m/d/Y", strtotime($post->day));?>');
            timeu.push('<?php echo $post->timeset;?>');
            msg.push('<?php echo $post->textarea;?>')
        </script>
    <?php
    }
    ?>
    <script type="text/javascript">
        setInterval(function(){ 
            // var date = new Date().toLocaleString("en-US", {timeZone: time_zone});
            var date = new Date().toLocaleString("en-US", {timeZone: time_zone, timeZoneName: "short",hour12: false})
            // alert(date);
            var result = date.split(',');
            var date1 = result[0];
            // alert(date1);
            var time = result[1];
            var result1 = time.split(' ');
            var time1 = result1[1];

            for (var i = 0; i < 9; i++) { 
                if ((date1 == day[i]) && (time1 == timeu[i])) {
                    jQuery('.modal-body').text(msg[i]);
                    jQuery("#exampleModal").modal('show');
                }
            }
        }, 1000);
    </script>

The values in date1 and day[i] , time1 & timeu[i] are coming as same when i alerted the values. so the string values are also same, but it dosent enter into the loop. i have tried using both"===" and "strcmp".Nothing Seems to Work. Can anyone provide me an insight?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.307848 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO