0

need help in inserting a php inside this script, heres the code

<script type="application/javascript">
            var eventData = [
                {
                date:"2015-03-01",
                badge:false,
                title:"Example 1"
                },
            ];
            $(document).ready(function () {
            $("#my-calendar").zabuto_calendar({
              data: eventData
            });
            });
            </script>

example i just want to declare a varible like $date=$row['date'];
date:"<?php echo $date ?>",

but its not working need help, thanks for help in advance :)

5
Contributors
4
Replies
20
Views
2 Years
Discussion Span
Last Post by rubberman
0

You can add php code in script, but you should have page with php extention and variable $date should not empty.

like

$date = "10-10-2015";
<script type="application/javascript">
  var Date = <?php echo $date?>;
 </script>

That should work

Thanks

Edited by pritaeas: Fixed markdown.

0

Makeitonline, I believe you need a semicolon after $date inside the php tags. All other stuff being correct, it should work after that.

0
    <script type="application/javascript">
        var eventData = [
            {
            date:"<?php echo date('Y-m-d') ?>",
            badge:false,
            title:"Example 1"
            },
        ];
        $(document).ready(function () {
          $("#my-calendar").zabuto_calendar({
            data: eventData
          });
        });
        </script>

Edited by pritaeas

0

I find that embedding php inside javascript or html to be very problematic and difficult to debug. I prefer to build up my javascript and html inside of php where adding the variables is trivial. Then the javascript or html that is sent to the client is clean, and performs better.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.