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 :)

Recommended Answers

All 4 Replies

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

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

    <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>

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.