I have a webpage made of a lot of PHP and Jquery/javascript
I have a function that runs when a submit button is clicked
$("#yesterday").click(function(){
var $date = $.datepicker.parseDate('yymmdd','<?php echo $_POST['date']; ?>');
var julDate = $.datepicker.formatDate('yyoo',new Date($date));
Number(julDate);
julDate = julDate - 1;
String(julDate);
var $date = $.datepicker.parseDate('yyoo',julDate);
var julDate = $.datepicker.formatDate('yymmdd',new Date($date));
var $longDate = $.datepicker.formatDate('DD MM d, yy',new Date($date));
$("#date").val(julDate);
$("#longdate").val($longDate);
$("#orwell_btn").click();
return false;
});
This function works PERFECTLY it reduces the date by 1 and reloads the page and executes my SQL query returnning all the correct info
if I change the fifth line and make the function liek so:
$("#tomorrow").click(function(){
var $date = $.datepicker.parseDate('yymmdd','<?php echo $_POST['date']; ?>');
var julDate = $.datepicker.formatDate('yyoo',new Date($date));
Number(julDate);
julDate = julDate + 1;
String(julDate);
var $date = $.datepicker.parseDate('yyoo',julDate);
var julDate = $.datepicker.formatDate('yymmdd',new Date($date));
var $longDate = $.datepicker.formatDate('DD MM d, yy',new Date($date));
$("#date").val(julDate);
$("#longdate").val($longDate);
$("#orwell_btn").click();
return false;
});
the function doesn’t complete and my page loads but as if it would on the very first load (which I have logic to handle but it should be advancing by 1 day ie doing the opposite of the yesterday button)
seems very odd to me
Number(julDate)returns a number with the parsed value.It doesn’t actually change anything.
Therefore,
julDate + 1is string concatenation.You want
julDate = Number(julDate).