Results 1 to 7 of 7

Thread: Mystery Javascript

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default Mystery Javascript

    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.

    Code:
    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;

    Code:
    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);
    }

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Commented:
    Code:
    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.
    }
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    kuau (06-13-2008)

  4. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    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??

    Code:
    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?

    Code:
    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.

    Code:
    $Check_Days = (mktime(0,0,0,$Sel2_Month,$Sel2_Day,$Sel2_Year)) - (mktime(0,0,0,$Sel1_Month,$Sel1_Day,$Sel1_Year));
    Last edited by kuau; 06-13-2008 at 11:57 AM. Reason: forgot code tags

  5. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Ok, this:
    Code:
    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:
    PHP Code:
    $Check_Days = (mktime(0,0,0,$Sel2_Month,$Sel2_Day,$Sel2_Year)) - (mktime(0,0,0,$Sel1_Month,$Sel1_Day,$Sel1_Year)); 
    To this:
    PHP Code:
    $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:
    PHP Code:
    $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.
    Jeremy | jfein.net

  6. The Following User Says Thank You to Nile For This Useful Post:

    kuau (06-13-2008)

  7. #5
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    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:

    Code:
    $Sel2_Day int;
    Code:
    int $Sel2_Day;
    Code:
    $Sel2_Day long;
    Last edited by kuau; 06-13-2008 at 12:28 PM. Reason: sp

  8. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Did you try searching Google for the answer to that?
    Jeremy | jfein.net

  9. #7
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •