secretscenario
04-01-2009, 09:50 PM
Hi guys, I'm teaching myself JavaScript, and am already fluent in PHP, but I cannot seem to identify the function causing the problem on the Swazze Calendar date picker I'm using. I've adjusted the code to the following:
function prepcalendar(hd,cm,cy) {
now=new Date();
sd=now.getDate();
td=new Date();
td.setDate(1);
td.setFullYear(cy);
td.setMonth(cm);
cd=td.getDay();
getObj('mns').innerHTML=mn[cm]+ ' ' + cy;
marr=((cy%4)==0)?mnl:mnn;
for(var d=1;d<=42;d++) {
f_cps(getObj('v'+parseInt(d)));
if ((d >= (cd -(-1))) && (d<=cd-(-marr[cm]))) {
dip=((d-cd < sd)&&(cm==sccm)&&(cy==sccy));
htd=((hd!='')&&(d-cd==hd));
if (dip)
f_cpps(getObj('v'+parseInt(d)));
else if (htd)
f_hds(getObj('v'+parseInt(d)));
else
f_cps(getObj('v'+parseInt(d)));
getObj('v'+parseInt(d)).onmouseover=(dip)?null:cs_over;
getObj('v'+parseInt(d)).onmouseout=(dip)?null:cs_out;
getObj('v'+parseInt(d)).onclick=(dip)?null:cs_click;
getObj('v'+parseInt(d)).innerHTML=d-cd;
calvalarr[d]=''+cy+'/'+(cm-(-1))+'/'+(d-cd);
} else {
getObj('v'+d).innerHTML=' ';
getObj('v'+parseInt(d)).onmouseover=null;
getObj('v'+parseInt(d)).onmouseout=null;
getObj('v'+parseInt(d)).style.cursor='default';
}
}
}
The section:
calvalarr[d]=''+cy+'-'+(cm-(-1))+'-'+(d-cd);
...is clearly what outputs the date format on the input field. Of course, the original section:
calvalarr[d]=''+(d-cd)+'/'+(cm-(-1))+'/'+cy;
...was not what I was looking for, because I'd like to have the PHP date format outputted so I can have the date placed into my database.
I'm here today to ask if anyone can help me identify and/or provide any help as to why if you select a date the first time around, it's placed onto the input field like so:
2009/4/1 (Which is what I'm aiming for as an output)
...but if you click the field and select another date without refreshing the page, it's outputted as this:
1/4/2
Where it still thinks the output format (DD-MM-YYYY), then the code fails to function properly.
Thanks so much for any help at all if so, and for just reading.
:]
function prepcalendar(hd,cm,cy) {
now=new Date();
sd=now.getDate();
td=new Date();
td.setDate(1);
td.setFullYear(cy);
td.setMonth(cm);
cd=td.getDay();
getObj('mns').innerHTML=mn[cm]+ ' ' + cy;
marr=((cy%4)==0)?mnl:mnn;
for(var d=1;d<=42;d++) {
f_cps(getObj('v'+parseInt(d)));
if ((d >= (cd -(-1))) && (d<=cd-(-marr[cm]))) {
dip=((d-cd < sd)&&(cm==sccm)&&(cy==sccy));
htd=((hd!='')&&(d-cd==hd));
if (dip)
f_cpps(getObj('v'+parseInt(d)));
else if (htd)
f_hds(getObj('v'+parseInt(d)));
else
f_cps(getObj('v'+parseInt(d)));
getObj('v'+parseInt(d)).onmouseover=(dip)?null:cs_over;
getObj('v'+parseInt(d)).onmouseout=(dip)?null:cs_out;
getObj('v'+parseInt(d)).onclick=(dip)?null:cs_click;
getObj('v'+parseInt(d)).innerHTML=d-cd;
calvalarr[d]=''+cy+'/'+(cm-(-1))+'/'+(d-cd);
} else {
getObj('v'+d).innerHTML=' ';
getObj('v'+parseInt(d)).onmouseover=null;
getObj('v'+parseInt(d)).onmouseout=null;
getObj('v'+parseInt(d)).style.cursor='default';
}
}
}
The section:
calvalarr[d]=''+cy+'-'+(cm-(-1))+'-'+(d-cd);
...is clearly what outputs the date format on the input field. Of course, the original section:
calvalarr[d]=''+(d-cd)+'/'+(cm-(-1))+'/'+cy;
...was not what I was looking for, because I'd like to have the PHP date format outputted so I can have the date placed into my database.
I'm here today to ask if anyone can help me identify and/or provide any help as to why if you select a date the first time around, it's placed onto the input field like so:
2009/4/1 (Which is what I'm aiming for as an output)
...but if you click the field and select another date without refreshing the page, it's outputted as this:
1/4/2
Where it still thinks the output format (DD-MM-YYYY), then the code fails to function properly.
Thanks so much for any help at all if so, and for just reading.
:]