The jquery datepicker plugin works, but I’d like to have onSelect triggering a function which opens a page in a new tab.
The jquery datepicker plugin works, but I’d like to have onSelect triggering a function which opens a page in a new tab.
$("#dp").datepicker({
beforeShowDay: highlightDays,
//works perfectly fine
onSelect: function(dates) { window.open('/en/calendar/' + dates, '_self'); },
});
var dates = [new Date(2011, 4 - 1, 28), new Date(2011, 5 - 1, 10),];
//does not work
onSelect: function(links) { window.open('/en/trip/' + links, '_self'); },
var links = [new Link('link1'), new Link('link2'),];
the js:
$( "#toggleDP" ).click(function() { $("#dp ").datepicker('show'); });
$("#dp").datepicker({
changeMonth: true,
changeYear: true,
showOn: 'button',
showButtonPanel: true,
buttonImageOnly: true,
buttonImage: "0.gif",
dateFormat: 'yy-mm-dd',
beforeShowDay: highlightDays,
onSelect: function(dates) { window.open('/en/calendar/' + dates, '_self'); },
});
var links =[new Link('test'), new Link('test1'), ];
var dates = [new Date(2011, 4 - 1, 28), new Date(2011, 5 - 1, 10), ];
var txt = ['test','test1',];
function highlightDays(date) {
for (var i = 0; i < dates.length; i++) {
if (dates[i]-date==0) {
return [true, 'markedDay', txt[i],];
}
}
return [false, ''];
}
if i were to set onSelect to function(links) { window.open(‘/en/trips/’ + links, ‘_self’); }, then for some unknown reasons, it opens an URL with the corresponding DATE not with the corresponding link.
Here is the onSelect handler syntax:
And explanation from the docs:
So when you say:
So passing as a parameter links is not actually the array you think it is but inside the handler the context is changed. i.e. links refers to the selected date as mentioned above.