PDA

View Full Version : Mystery Javascript



kuau
06-13-2008, 10:36 AM
Does anyone know what these scripts do? They are both run at the top of a file, one after the other. Apart from being related to dates, I have no clue, and they are causing error messages in the file itself. Thanks.


var expDays = 30;
var expDate = new Date();
expDate.setTime(expDate.getTime() + (24 * 60 * 60 * 1000 * expDays));

var id = GetCookie('Memo_Date');

var date = new Date();
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
/* var year = (yy < 1000) ? yy + 1900 : yy; */
var year = (yy < 1000) ? yy + 2000 : yy;

var Sel1_Date = month + "/" + day + "/" + year;
var Sel2_Date = Sel1_Date;
var MDate = Sel1_Date + "-" + Sel2_Date;




function save_date () {
var Sel1_Date = document.database.Sel1_Day.value + "/" + document.database.Sel1_Month.value + "/" + document.database.Sel1_Year.value;
var Sel2_Date = document.database.Sel2_Day.value + "/" + document.database.Sel2_Month.value + "/" + document.database.Sel2_Year.value;
var now_date = Sel1_Date + "-" + Sel2_Date;
SetCookie ("Memo_Date",now_date);
}

Nile
06-13-2008, 11:40 AM
Commented:


var expDays = 30; //days
var expDate = new Date(); //make a date object
expDate.setTime(expDate.getTime() + (24 * 60 * 60 * 1000 * expDays)); //set the time for the date object

var id = GetCookie('Memo_Date'); //get cookie, memo_date

var date = new Date(); //make another dataobject
var d = date.getDate(); //get the data from the above
var day = (d < 10) ? '0' + d : d; //if d is less than ten, day equals 0+d, otherwhise it just equals d
var m = date.getMonth() + 1; //get the month +1
var month = (m < 10) ? '0' + m : m; //if m is less than ten, month equals 0+m, otherwhise it just equals m
var yy = date.getYear();
/* var year = (yy < 1000) ? yy + 1900 : yy; */
var year = (yy < 1000) ? yy + 2000 : yy; //if yy(year) is lesds than 1000 it equals yy+2000, if not it equals yy.

var Sel1_Date = month + "/" + day + "/" + year;
var Sel2_Date = Sel1_Date;
var MDate = Sel1_Date + "-" + Sel2_Date;
//just adding all the dates together.
function save_date () {
var Sel1_Date = document.database.Sel1_Day.value + "/" + document.database.Sel1_Month.value + "/" + document.database.Sel1_Year.value;
var Sel2_Date = document.database.Sel2_Day.value + "/" + document.database.Sel2_Month.value + "/" + document.database.Sel2_Year.value;
var now_date = Sel1_Date + "-" + Sel2_Date; //put the date in an input value
SetCookie ("Memo_Date",now_date); //set cookie, or overwrite.
}

kuau
06-13-2008, 11:56 AM
Thanks, Nile. Some of it makes sense I guess but some not. For instance, this seems to me to subtract 2 identical dates which would give 0??


var now_date = Sel1_Date + "-" + Sel2_Date; //put the date in an input value
I still don't understand what it accomplishes. What is the point of it? Why does it give these error messages?


Warning: mktime() expects parameter 5 to be long, string given in /home1/mauiretr/public_html/_car/php/load_stats_data.php on line 43

Warning: mktime() expects parameter 5 to be long, string given in /home1/mauiretr/public_html/_car/php/load_stats_data.php on line 43


Here is line 43. I thought this was fixed but it came back.


$Check_Days = (mktime(0,0,0,$Sel2_Month,$Sel2_Day,$Sel2_Year)) - (mktime(0,0,0,$Sel1_Month,$Sel1_Day,$Sel1_Year));

Nile
06-13-2008, 12:01 PM
Ok, this:


var now_date = Sel1_Date + "-" + Sel2_Date; //put the date in an input value
Just displays something like today: it's 6-13, ahh friday the 13th!!!
Now, try changing:


$Check_Days = (mktime(0,0,0,$Sel2_Month,$Sel2_Day,$Sel2_Year)) - (mktime(0,0,0,$Sel1_Month,$Sel1_Day,$Sel1_Year));

To this:

$Check_Days = mktime(0,0,0,$Sel2_Month,$Sel2_Day,$Sel2_Year);
$Check_Days = $Check_Days - (mktime(0,0,0,$Sel1_Month,$Sel1_Day,$Sel1_Year));

If that doesn't work, try this:

$Check_Days = mktime(0,0,0,$Sel2_Month,$Sel2_Day,$Sel2_Year);
$Check_Days -=(mktime(0,0,0,$Sel1_Month,$Sel1_Day,$Sel1_Year));

If that doesn't work, than it's a problem with the mktime witch I know nothing about.

kuau
06-13-2008, 12:27 PM
Thanks Nile but both of those give the same error. How do I assign a long integer value to $Sel2_Day?

I tried these but got a different error:


$Sel2_Day int;


int $Sel2_Day;


$Sel2_Day long;

Nile
06-13-2008, 06:59 PM
Did you try searching Google for the answer to that?

kuau
06-13-2008, 11:24 PM
Yes, but just got a ton of stuff showing how to assign a value, not a datatype. I originally tried setting a literal value to $Sel2_Day etc and it screwed up the whole thing. If this were so easy, I wouldn't be asking. I have already spent countless hours trying everything to get rid of these messages. Obviously the guy who originally wrote the code couldn't figure it out either or he wouldn't have left it like this and given up. I thought it would be a simple thing for a php programmer, but apparently not. I am just the css person and unfortunately cannot do my job when error messages keep screwing up the page and filling up the error logs. Perhaps you can please tell me what to type into Google to find the solution to this problem. Thank you.