jquery - Changing table values using php input -
i making calendar using html tables , filling input using jquery. it's not working , nothing gets populated in table. empty table displayed after pressing button.
here code, plz point out wrong:
<?php date_default_timezone_set('asia/kolkata'); $inputmonth = date('y-m-d'); $totalday = date("t", strtotime($inputmonth)); $month = date("m" , strtotime($inputmonth)); $year = date("y" , strtotime($inputmonth)); $getdate = getdate(mktime(null, null, null, $month, 1, $year)); $first_day = $getdate["weekday"]; $day_of_week = date('n', strtotime($first_day)); ?> <html> <head> <title>calendar test</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function() { $("button").click(function() { var firstdaynumber = <? php echo $day_of_week; ?> ; var nodays = <? php echo $totalday; ?> ; var currentmonth = <? php echo $month; ?> var = 1; $("caption").html(currentmonth); $('table tr').each(function() { var $row = $(this); $row.children().each(function() { var $cell = $(this); if (i >= firstdaynumber && <= nodays) { $cell.html(i); } else { $cell.addclass("closed"); } ++i; }); }); }); }); </script> <style> table { position: relative; border: 1px solid black; height: auto; width: auto; table-layout: fixed; border-collapse: collapse; } td { display: inline; border: 1px solid black; position: static; text-align: center; font-size: 1.5em; padding: 12px 20px; } </style> </head> <body> <table id="tbl"> <caption style="font-size: 1.7em"></caption> <br> <tr> <th>mon</th> <th>tue</th> <th>wed</th> <th>thu</th> <th>fri</th> <th>sat</th> <th>sun</th> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <tr> <td></td> <td></td> </tr> </tr> </table> <button>generate</button> </body>
hey code had few syntax errors (on lines 21, 22 , 23 [php syntax errors]). there javascript syntax error on line 23. corrected code given below.
<?php date_default_timezone_set('asia/kolkata'); $inputmonth = date('y-m-d'); $totalday = date("t", strtotime($inputmonth)); $month = date("m" , strtotime($inputmonth)); $year = date("y" , strtotime($inputmonth)); $getdate = getdate(mktime(null, null, null, $month, 1, $year)); $first_day = $getdate["weekday"]; $day_of_week = date('n', strtotime($first_day)); ?> <html> <head> <title>calendar test</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function() { $("button").click(function() { var firstdaynumber = <?php echo $day_of_week; ?> ; var nodays = <?php echo $totalday; ?> ; var currentmonth = <?php echo $month; ?>; var = 1; $("caption").html(currentmonth); $('table tr').each(function() { var $row = $(this); $row.children().each(function() { var $cell = $(this); if (i >= firstdaynumber && <= nodays) { $cell.html(i); } else { $cell.addclass("closed"); } ++i; }); }); }); }); </script> <style> table { position: relative; border: 1px solid black; height: auto; width: auto; table-layout: fixed; border-collapse: collapse; } td { display: inline; border: 1px solid black; position: static; text-align: center; font-size: 1.5em; padding: 12px 20px; } </style> </head> <body> <table id="tbl"> <caption style="font-size: 1.7em"></caption> <br> <tr> <th>mon</th> <th>tue</th> <th>wed</th> <th>thu</th> <th>fri</th> <th>sat</th> <th>sun</th> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <tr> <td></td> <td></td> </tr> </tr> </table> <button>generate</button> </body>
Comments
Post a Comment