My jquery datepicker has the following code:
$(document).ready(function() {
var event = ['14 april 2017', '25 april 2017', '1 april 2017'];
$('#datepicker').datepicker({
inline: true,
showOtherMonths: true,
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
beforeShowDay: highlightDays,
onSelect: function(dateText, inst){
showpopup();
getdatespan();
}
});
function highlightDays(date) {
for (var i = 0; i < event.length; i++) {
if (new Date(event[i]).toString() == date.toString()) {
return [true, 'ui-state-event', ''];
}
}
return [true, ''];
}
...
The bit I'd like to focus on is the variable 'event' that is being used to provide dates for the highlightDays
function. As it is above, the code works perfectly and successfully highlights the date in the variable. However, those dates have been manually typed in by myself.
Below is the code within my calendar.php file:
$findEventStartdates = $pdo->prepare('SELECT startdate FROM calendar WHERE username=?');
//execute query with variables
$findEventStartdates->execute([$username]);
($eventStartdates = $findEventStartdates->fetchAll(PDO::FETCH_COLUMN));
When printed, this shows the following output:
Array ( [0] => 14 april 2017 [1] => 25 april 2017 [2] => 1 april 2017)
My question is how can i get whatever is outputted in that PDO to be used as the variable for the datepicker?
In the PHP file i tried the following:
$highlightEvents = implode("', '",$eventStartdates);
echo <<<_END
<input type="text" name="eventHighlight" id="eventHighlight" value="'$highlightEvents'">
_END;
This shows:
'14 april 2017', '25 april 2017', '1 april 2017'
in the textbox and then tried this with the jquery:
var event = [$("#eventHighlight").text];
but this did not work. So any alteration to this or different way of using the Array would be appreciated.
Thank you.