/    Sign up×
Community /Pin to ProfileBookmark

JS Calender/Calc tool – Help needed

I have this little tool in JavaScript that Im trying to make some edits to, tryed a few times and had some problems so starting over again.

Basically this tool works out when a check will clear in the UK by clicking on a date in the calender but I need to make 2 main tweaks.

  • 1.

    Add a new cleared for fate (unreturnable) value to it (currently gives interest and cleared) which is normally six working days later


  • having problems adding the additional value.

  • 2.

    An addition date selection in the forum of a drop down list.
    (would be nice if it was already starting on today and had real dates)

  • Heres the code can anyone help me do this cleanly and properly?

    [URL=”http://dfgowans.workingtitledesign.com/personal/bankcheck.zip”]http://dfgowans.workingtitledesign.com/personal/bankcheck.zip[/URL]

    to post a comment
    JavaScript

    3 Comments(s)

    Copy linkTweet thisAlerts:
    @gowans007authorNov 13.2007 — could really use some help guys heres a striped down version of one of the buggy ones.

    http://dfgowans.workingtitledesign.com/personal/bankcheck2.zip

    The new result (shown now in yellow) should be after the others a couple of work days after the clear.



    <select name="bank" onChange="calculate(1);">

    <option value="3,5,1,[B]7[/B]">My Bank

    <option value="3,6,1,[B]8[/B]">Other UK Bank

    <option value="5,7,1,[B]8"[/B]>Post Office

    </select>[/QUOTE]



    [B]PS for use only in IE[/B]
    Copy linkTweet thisAlerts:
    @gowans007authorNov 13.2007 — Any ideas guys, just cant get this new variable to be part of the tool properly

    [CODE] <script language="javascript">

    today=new Date();
    today.setHours(24);
    today.setMinutes(0);
    today.setSeconds(0);
    today.setMilliseconds(0);
    now=new Date(today);
    oneDay=1000*60*60*24;
    dowtxt=new Array("S","M","T","W","T","F","S");
    dowFtxt=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    moy=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    clrAry=new Array("#FFFFFF","#e3e3e3","#a0a0a0","#ffcc66");
    var datesAry;
    selectedDate=0;

    info=new Array("<b>Cheque Paid in on:</b><b>", "", "Interest will start to be paid on:", "", "<b><font color=white>Cheque Available for Withdrawl:</b><b>", "", "<i>Certainty (cleared for fate):", "");





    var todayIsBusinessDay=true;

    holidays=new Array();

    holidays[holidays.length]="January 1 2008,New Years Day";
    holidays[holidays.length]="March 21 2008,Good Friday";
    holidays[holidays.length]="March 24 2008,Easter Monday";
    holidays[holidays.length]="May 5 2008,May Day";
    holidays[holidays.length]="May 26 2008,Spring";
    holidays[holidays.length]="August 25 2008,Summer";
    holidays[holidays.length]="December 25 2008,Christmas";
    holidays[holidays.length]="December 26 2008,Boxing Day";

    holidays[holidays.length]="January 1 2007,New Years Day";
    holidays[holidays.length]="April 6 2007,Good Friday";
    holidays[holidays.length]="April 9 2007,Easter Monday";
    holidays[holidays.length]="May 7 2007,May Day";
    holidays[holidays.length]="May 28 2007,Spring";
    holidays[holidays.length]="August 27 2007,Summer";
    holidays[holidays.length]="December 25 2007,Christmas";
    holidays[holidays.length]="December 26 2007,Boxing Day";



    for(i=0;i<holidays.length;i++)
    { holidays[i]=holidays[i].split(",");
    holidays[i][0]=new Date(holidays[i][0]);
    };


    function initialize()
    { makeCalendar();
    return true;
    };


    function makeCalendar()
    { document.getElementById("month").innerHTML=moy[today.getMonth()];
    document.getElementById("year").innerHTML=today.getYear();
    html='<table border=0><tr>';

    for(i=0;i<dowtxt.length;i++)
    html+='<td align="center">'+dowtxt[i]+'</td>';
    holCntr=0;
    holTxtAry=new Array();
    datesAry=new Array("");
    twoMonths=new Date(today);

    for(k=0;k<2;k++)
    { first=new Date(twoMonths);
    first.setDate(1);
    day=1-first.getDay();
    flag=true;

    while(flag==true)
    { html+='</tr><tr>';

    for(i=0;i<7;i++)
    { clr=0;
    altTxt="";

    for(j=0;j<holidays.length;j++)
    {

    if(first.getTime()==holidays[j][0].getTime())

    if(first.getDay()%6==0 || holCntr>0)
    { if(holTxtAry[holCntr-1]!=holidays[j][1])
    { holTxtAry[holCntr]=holidays[j][1];
    holCntr++;
    };
    }
    else
    { clr=2;
    altTxt=holidays[j][1]; };
    };

    if(holCntr>0 && first.getDay()%6>0)
    { holCntr--;
    altTxt=holTxtAry[0];

    for(j=0;j<holCntr;j++)
    holTxtAry[j]=holTxtAry[j+1];
    clr=3;
    };

    clr=(first.getDay()%6>0 || flag==false || day<1)?clr:1;


    if(Math.floor(first.getTime()/6000)==Math.floor(now.getTime()/6000)) {
    if(clr!=0) todayIsBusinessDay=false;
    clr=3;
    }
    dayHref="&nbsp;";
    bgclr=0;

    if(day>0 && flag==true)
    { dayHref='<a href="javascript:void(0);" onclick="calculate(0);" title="'+altTxt+'" class="link">'+day+'</a>';
    datesAry[datesAry.length]=clr;
    bgclr=clr;
    };
    html+='<td style="border:1px #e4e4e4 solid; background-color:'+clrAry[bgclr]+';">'+dayHref+'</td>';
    day++;

    if(day>0)
    first.setDate(day);
    flag=(first.getMonth()==twoMonths.getMonth())
    };
    };
    twoMonths.setMonth(today.getMonth()+1);
    html+='</tr></table>';
    };
    document.getElementById("dates").innerHTML=html.substring(0,html.indexOf("</table>")+8);
    };



    function change(how)
    { newDate=new Array("prevMonth","nextMonth","prevYear","nextYear");

    for(i=0;i<newDate.length;i++)
    newDate[newDate[i]]="today.set"+newDate[i].substring(4,9)+"(today.get"+newDate[i].substring(4,9)+"()+"+((i&1)*2-1)+");";
    eval(newDate[how]);

    makeCalendar();
    };




    function calculate(manual)
    { if(selectedDate>0 || manual==0)
    { bgclr=new Array("#ccffff","#99ccff","#0099FF","#ffffcc");
    data=new Array();

    for(i=0;i<2;i++)

    data[i]=document.frm.elements[i+1].options[document.frm.elements[i+1].selectedIndex].value.split(",");
    selectedDate=which=(manual==1)?selectedDate:event.srcElement.innerHTML*1;
    allHrefs=document.getElementById("dates").getElementsByTagName("A");

    for(i=0;i<allHrefs.length;i++)
    { allHrefs[i].parentElement.style.backgroundColor=clrAry[datesAry[i+1]];
    allHrefs[i].className="link";
    };


    allHrefs[which-1].parentElement.style.backgroundColor=bgclr[0];
    allHrefs[which-1].className="linkBold";




    for(i=0;i<2;i++)
    data[0][i]=data[0][i]*1+(((document.frm.cutoff.checked)?data[0][2]*1:0));
    while((datesAry[which]!=0 && datesAry[which]!=3) || (datesAry[which]==3 && !todayIsBusinessDay))
    which++;


    for(i=0;i<2;i++)
    data[0][i]=data[0][i]*1+((((datesAry[which]==0 || datesAry[which]==3 && todayIsBusinessDay))?data[0][2]*1:0))-1;
    while((datesAry[which]!=0 && datesAry[which]!=3) || (datesAry[which]==3 && !todayIsBusinessDay))
    which++;


    for(i=0;i<2;i++)
    data[0][i]=data[0][i]*1+(data[1][i]*1+(((datesAry[which]==0 || datesAry[which]==3 && todayIsBusinessDay))?data[0][2]*1:0))-1;
    while((datesAry[which]!=0 && datesAry[which]!=3) || (datesAry[which]==3 && !todayIsBusinessDay))
    which++;






    info[1]=frmtDate(which);

    for(i=0;i<3;i++)
    { cntr=which;

    while(data[0][i]>0 && cntr<=datesAry.length)
    { cntr++;
    if(datesAry[cntr]==0 || (datesAry[cntr]==3 && todayIsBusinessDay))
    data[0][i]--;
    };

    if(cntr<=allHrefs.length)
    { allHrefs[cntr-1].parentElement.style.backgroundColor=bgclr[i+1];
    allHrefs[cntr-1].className="linkBold";
    };
    info[i*2+3]=frmtDate(cntr);
    };





    html='<table width=250 border=1 cellpadding=6 cellspacing=0 bordercolor=#3366FF>';

    for(i=0;i<8;i+=2)
    {
    html+='<tr><td bgcolor="'+bgclr[i/2]+'">';


    html+=''+info[i]+'<br>'+info[i+1]+'';


    html+='</td></tr>'

    }




    document.getElementById("result").innerHTML=html+'</table>';
    with(document.frm)
    { dtl="You paid in your cheque ";
    dtl+="into a "+acc.options[acc.selectedIndex].text+" account <br>";
    cutTxt=((cutoff.checked)?" after":" before")+" cut-off time ";
    dtl+="on "+info[1]+((bank.selectedIndex!=7)?cutTxt:" ");
    dtl+="at "+bank.options[bank.selectedIndex].text+".<br> ";

    dtl+="<br>This means that your cheque will clear on:<br><b> "+info[5]+".";
    };
    document.getElementById("detail").innerHTML=dtl;
    };

    };




    function frmtDate(d)
    { tempDate=new Date(today);
    tempDate.setDate(d);
    dw=dowFtxt[tempDate.getDay()];
    dd=tempDate.getDate();
    mm=moy[tempDate.getMonth()];
    yy=tempDate.getYear();
    return dw+","+dd+" "+mm+" "+yy;
    };


    </script>[/CODE]


    Something wrong in the calculate for loops?
    Copy linkTweet thisAlerts:
    @gowans007authorNov 13.2007 — [B]No ideas guys?



    Any clues at what to look at or any other tricks?[/B]


    Really stuck & wana try and get this done in the next few hours and Im just at a brickwall

    Any help no matter how little would be so good
    ×

    Success!

    Help @gowans007 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.5,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...