I was practicing with data picker in jQuery UI and I got into problem that I could't solve.
I wanted to calculate the difference of given date (from date picker) and today's date in days, after user clicked calculate button.
I get this error:
Uncaught ReferenceError: select is not defined(anonymous
function)
j
k.fireWithjQuery.js: 2
m.extend.readyjQuery.js: 2
J
Here is my code:
$(document).ready(function() {
$("#calculate").click(function() {
var d1 = $(".date-pick").datepicker("setDate", new Date());
var d2 = $("#startDate").datepicker('getDate');
var diff = 0;
if (d1 && d2) {
diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000);
}
$('#calculated').val(diff);
});
$("#startDate").datepicker({
onSelect: select
});
});
Here is my plete source code
I was practicing with data picker in jQuery UI and I got into problem that I could't solve.
I wanted to calculate the difference of given date (from date picker) and today's date in days, after user clicked calculate button.
I get this error:
Uncaught ReferenceError: select is not defined(anonymous
function)
j
k.fireWithjQuery.js: 2
m.extend.readyjQuery.js: 2
J
Here is my code:
$(document).ready(function() {
$("#calculate").click(function() {
var d1 = $(".date-pick").datepicker("setDate", new Date());
var d2 = $("#startDate").datepicker('getDate');
var diff = 0;
if (d1 && d2) {
diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000);
}
$('#calculated').val(diff);
});
$("#startDate").datepicker({
onSelect: select
});
});
Here is my plete source code
Share Improve this question asked Jan 13, 2015 at 18:46 Node.JSNode.JS 1,6347 gold badges55 silver badges131 bronze badges 1-
5
It's not defined because you didn't define it anywhere, you just randomly typed
select
as a value in an object, and there's no variable namedselect
in your code. – adeneo Commented Jan 13, 2015 at 18:47
1 Answer
Reset to default 4You simply have not defined select
function anywhere in your source code (all your custom js-code is currently in your index.html, so it is easy to figure it out), but you are trying to use it as onSelect
event handler.