Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
115
rated 0 times [  119] [ 4]  / answers: 1 / hits: 11471  / 11 Years ago, mon, february 10, 2014, 12:00:00

Right now I am using a manually inputted array of dates called disable to disable dates in the jquery UI datepicker with the beforeShowDay method. This is working fine, however, I have a php variable $disablethese which is storing a dynamic array of dates to disable. For some reason, I can't seem to convert my php array into a javascript array (which I'm calling unavailabledates). It doesn't throw any errors but it just doesn't work block out the dates the same way as the static array.



<script type=text/javascript>
var unavailabledates = <?php echo json_encode($disablethese); ?>;
</script>
<script src=js/datepicker-admin.js></script>





Here is datepicker-admin.js



 $(document).ready(function() {
var disable = [2014-01-03,2014-01-13,2014-01-23];
$('#fromDate').datepicker({
beforeShowDay: function(date) {
if($.inArray($.datepicker.formatDate('yy-mm-dd', date ), disable) > -1) {
return [false, highlighted, Booked out];
} else {
return [true, , available];
}
}
});
});

More From » php

 Answers
15

you can use $.parseJSON function.



<script type=text/javascript>
var unavailabledates = $.parseJSON('<?php echo json_encode($disablethese); ?>');
</script>
<script src=js/datepicker-admin.js></script>

[#47891] Sunday, February 9, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
conorm

Total Points: 339
Total Questions: 104
Total Answers: 104

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
conorm questions
Thu, Jun 11, 20, 00:00, 4 Years ago
Sun, Mar 8, 20, 00:00, 4 Years ago
;