Date selection, accumulate, and assign values

Source: Internet
Author: User

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>

<Body>
<Form name = "form">

<Table>
<Tr>
<TD> current date: </TD>
<TD> <input type = "text" name = "U" value = "2009-01-01"> </TD>
</Tr>
<Tr>
<TD> days to add: </TD>
<TD> <input type = "text" name = "entry" id = "D" value = "" onkeyup = "Calculate ('D')"> </TD>
</Tr>
<Tr>
<TD> Number of weeks to be added: </TD>
<TD> <input type = "text" name = "entry" id = "W" value = "" onkeyup = "Calculate ('W')"> </TD>
</Tr>
<Tr>
<TD> Number of months to be added: </TD>
<TD> <input type = "text" name = "entry" id = "M" value = "" onkeyup = "Calculate ('M')"> </TD>
</Tr>
<Tr>
<TD> Number of years to be added: </TD>
<TD> <input type = "text" name = "entry" id = "Y" value = "" onkeyup = "Calculate ('y')"> </TD>
</Tr>
<Tr>
<TD> result: </TD>
<TD> <input name = "Twice"> </TD>
</Tr>
<! -- <Tr>
<TD> date to be added 2: </TD>
<TD> <input type = "text" name = "U" value = "2009/01/01"> </TD>
</Tr>
<Tr>
<TD> result 2: </TD>
<TD> <input name = "Twice"> </TD>
</Tr> -->
</Table>
</Form>
<Script language = "JavaScript">
Function dateadd (strinterval, numday, dtdate ){
VaR dttmp = new date (dtdate );
If (isnan (dttmp) dttmp = new date ();
Switch (strinterval ){
Case "S ":
Dttmp = new date (date. parse (dttmp) + (1000 * parseint (numday )));
Break;
Case "N ":
Dttmp = new date (date. parse (dttmp) + (60000 * parseint (numday )));
Break;
Case "H ":
Dttmp = new date (date. parse (dttmp) + (3600000 * parseint (numday )));
Break;
Case "D ":
Dttmp = new date (date. parse (dttmp) + (86400000 * parseint (numday )));
Break;
Case "W ":
Dttmp = new date (date. parse (dttmp) + (86400000*7) * parseint (numday )));
Break;
Case "M ":
Dttmp = new date (dttmp. getfullyear (), (dttmp. getmonth () + parseint (numday), dttmp. getdate (), dttmp. gethours (), dttmp. getminutes (), dttmp. getseconds ());
Break;
Case "Y ":
// Alert (dttmp. getfullyear ());
Dttmp = new date (dttmp. getfullyear () + parseint (numday), dttmp. getmonth (), dttmp. getdate (), dttmp. gethours (), dttmp. getminutes (), dttmp. getseconds ());
// Alert (dttmp );
Break;
}
VaR mstr = new string (dttmp. getmonth () + 1 );
VaR dstr = new string (dttmp. getdate ());
If (mstr. Length = 1 ){
Mstr = "0" + mstr;
}
If (dstr. Length = 1 ){
Dstr = "0" + dstr;
}
Return dttmp. getfullyear () + "-" + mstr + "-" + dstr;
}
</SCRIPT>
<Script language = "JavaScript">

Function calculate (type)
{
VaR entry = Document. getelementbyid (type). value; // you can determine whether the value is valid.
VaR uvalue = Document. Form. U. value;
Uvalue = uvalue. Replace ("-", "/"). Replace ("-","/");
// Alert (uvalue );
Document. Form. Twice. value = dateadd (type, entry, uvalue );
}
</SCRIPT>

</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.