Gladwin James Gladwin James - 1 month ago 9
HTML Question

Date picker(.js) not working in HTML editor but working in fiddle

This is the working format in fiddle
and below is the code i have used in my demo-site i have created a new folder name js and placed datepicker.js inside it. so i linked the following in my html.

<script type="text/javascript" src="js/datepicker.js"></script>


and my datapicker.js code is

$(function () {
$('#departure-date').datepicker({
numberOfMonths: 2,
showAnim: "fold",
showButtonPanel: true,
onSelect: (function (date) {
setTimeout(function () {
$('#return-date').datepicker('show');
}, 300)
$(this).val($(this).datepicker('getDate').toLocaleDateString());
})
});

$('#return-date').datepicker({
numberOfMonths: 2,
showAnim: "fold",
showButtonPanel: true,
onSelect: (function (date) {
$(this).val($(this).datepicker('getDate').toLocaleDateString());
})
});
});


and my html code is

<input id="departure-date" type="text" placeholder="Depart Date" >
<input type="text" id="return-date" placeholder="return Date">


but when i press the above button .js is not being called. please help

Answer

You need to include a version of jQuery. Download the latest release and put it in your js folder and link it like you did for datepicker.js or directly include it like this

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

If this does not work try

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

I am not sure if your single datepicker.js has and error, but if it does try the jquery-ui js which includes it.

I tested it with including the above 2 js sources and it worked fine.

If the direct link to the jquery site js does not work then it is another problem on your page that is not shown to us.