Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

My question may be simple or something similar to other question, But i am just unable to accomplish this task.

I am trying to disable some dates in datepicker dynamically. I am just running a query which gives a list of holidays.

$date[]=$year.'/'.$month.'/'.$day; // array 

and i am using implode so that i can have comma separated list

$abc=implode(',',$date);

so $abc contains dates.

Here is my javascript

    <script type="text/javascript">
//var Alldays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
/* var disable= '<?php echo $info; ?>'; // yyyy/MM/dd*/
var disableDates="<?php =$abc; ?>"; 

//var disableDays = ["Saturday", "Sunday"];
//var disableDates = ["2013/02/26", "2013/02/28"];
alert (disableDates);
function ShowDisableDates(date) {
ymd = date.getFullYear() + "/" + ("0" + (date.getMonth() + 1)).slice(-2) + "/" + ("0" + date.getDate()).slice(-2);
//alert(ymd);
//ymd= ("0" + (date.getMonth() + 1)).slice(-2) + "/" + ("0" + date.getDate()).slice(-2) + "/" + date.getFullYear();
day = new Date(ymd).getDay();
if ($.inArray(ymd, disableDates) < 0 ) {
return [true, "enabled", "Book Now"];
} else {
return [false, "disabled", "Sold Out"];
}
}
$(function() {
$("#datepicker").datepicker({beforeShowDay:ShowDisableDates});
});
</script>

But i am not able to access the dates from $abc to javascript.

If i declare them as static as

var disableDates = ["2013/02/26", "2013/02/28"];

It works fine

Please guide me to solve this, Thanks

share|improve this question

marked as duplicate by mario, Salman A, Felix Kling, code_burgar, Frank van Puffelen Feb 10 '13 at 22:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
Consider json_encode(), and turn on error_reporting. Your output syntax is wrong. It's <?= not <?php = –  mario Feb 9 '13 at 11:45

1 Answer 1

up vote 3 down vote accepted

If $abc is an array:

var disableDates = <?= json_encode($abc); ?>; 
share|improve this answer
    
You would want to remove the " –  hank Feb 9 '13 at 11:48
    
Ah yes, thanks :) –  nice ass Feb 9 '13 at 11:49
    
It worked, Thanks @OneTrickPony –  Ramaraju.d Feb 9 '13 at 11:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.