/    Sign up×
Community /Pin to ProfileBookmark

need help with javascript

[CODE]
<html>
<head>
<script language=”javascript”>
function getTgl(tgl)
{
if(tgl.value.charAt(1)==”/”)
{
tgl.value=”0″+tgl.value;
}
if(tgl.value.charAt(4)==”/”)
{
var x=tgl.value.substr(0,2);
var y=tgl.value.substr(3);
tgl.value=x+”/0″+y;
}
if(tgl.value.length==2)
{
tgl.value=tgl.value+”/”;
}
if(tgl.value.length==5)
{
tgl.value=tgl.value+”/”;
}

/*if((tgl.value.substr(1,2)<1) || (tgl.value.substr(1,2)>12))
{
alert(“Format Tanggal mm/dd/yyyy”);
tgl.value=tgl.value.replace(tgl.value.substr(0),””);
}*/

if((document.formdate.tstart.value.length==”10″) && (document.formdate.tend.value.length==”10″))
{
var day1=document.formdate.tstart.value.substr(3,4);
var day2=document.formdate.tend.value.substr(3,4);
var month1=document.formdate.tstart.value.substr(0,2);
var month2=document.formdate.tend.value.substr(0,2);
var year1=document.formdate.tstart.value.substr(6,9);
var year2=document.formdate.tend.value.substr(6,9);
if(month1==month2)
{
if((day1>day2) || (year1>year2))
{
alert(“End Date harus lebih besar dari Start Date”);
document.formdate.tend.value=document.formdate.tend.value.replace(document.formdate.tend.value.substr(0),””);
}
}
else if(month1<month2)
{}
else
{
alert(“End Date harus lebih besar dari Start Date”);
document.formdate.tend.value=document.formdate.tend.value.replace(document.formdate.tend.value.substr(0),””);
}

temp1=new Date(document.formdate.tstart.value);
temp2=new Date(document.formdate.tend.value);
var dayt1=temp1.getDate();
var dayt2=temp2.getDate();
var mont1=temp1.getMonth()+1;
var mont2=temp2.getMonth()+1;
var yeart1=temp1.getFullYear();
var yeart2=temp2.getFullYear();
document.formdate.start.value=mont1+”/”+dayt1+”/”+yeart1;
document.formdate.end.value=mont2+”/”+dayt2+”/”+yeart2;

var startdate=document.formdate.start.value;
var enddate=document.formdate.end.value;

var i=startdate;
var msg=[];

while(i<=enddate)
{
b=new Date(i);
b=b.getDay();
if(b=”0″)
b=(b.getMonth()+1)+b.getDate();+b.getYear();
document.write(msg[msg.length] =”<li>” +b+”<BR>”);
i=b.getDay()+1;
i++;

}
/*if(msg!=””)
{
document.writeln (“Weekend dates found:<ul>” + msg + ‘<BR>’);
}
else
{
document.write (“No weekend dates in that range”);
}*/
}
}
</script>
</head>
<body>
<table>
<tr>
<form name=”formdate”>
<td><input type=”hidden” name=”start” id=”tid”></td>
<td width=”100″><input type=”text” name=”tstart” onBlur=”tab()” maxlength=”11″ size=”8″ id=”pid” onKeyUp=”getTgl(this)” value=”<%=startDate%>”></td>
<td width=”105″>sampai dengan</td>
<td><input type=”hidden” name=”end” id=”tid2″></td>
<td width=”100″><input type=”text” name =”tend” maxlength=”11″ size=”8″ id=”pid2″ onKeyUp=”getTgl(this)” value=”<%=endDate%>”></td>
</tr></table><input type=submit name=”SUBMIT” value=”Test”></form>
</body>
</html>
[/CODE]

that’s my code, but doesn’t work yet. I’m new with javascript, so please help me.
in that’s code, I want to check between 2 dates have weekend and/or holiday or not.
example:
if I input text1(startDate)=”12/17/2009″ and text2(endDate)=”12/25/2009″. if i have done input endDate, then system will be check between that dates have weekend and/or holiday or not.so in this process doesn’t need click submit.this process will be put on onKeyUp.
so,, from that’s dates the result will be :
“Weekend and/or Holiday found:

>

Saturda, Dec, 19 2009
> Sunday, Dec, 20 2009
> Friday, Dec, 25 2009 “

but if from that’s dates haven’t weekend and/or holiday, the result will be :
“No weekend and/or holiday dates in that range”

and I dont know how to validate that dates.

thanks B4

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @sela_cullens 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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