JS implementation of dynamic date selection form

Source: Internet
Author: User
Tags date1 getdate

JS implementation of dynamic Date selection form, using the method:

Showdateselect ("Date1")

Where the parameter is the name of the table item select, and then you can use Date1.value to get the selected date.

<title> Dynamic Date Selection form </title>
<meta http-equiv= "Content-type" content= "text/html" charset= "gb2312" >
<script language= "JavaScript" >
<!--
function yearlist (num) {
var d=new Date ();
var t=d.getfullyear ();
var ystr= "";
for (Var i=t-num;i<=t+num;i++) {
ystr=ystr+ "<option value= '" +i+ (i==t "' selected>": "' >") +i+ "</option>";
}
return ystr;
}
function Monthlist () {
var d=new Date ();
var t=d.getmonth () +1;
Mstr= "";
for (Var i=1;i<=12;i++) {
mstr=mstr+ "<option value= '" +i+ (i==t "' selected>": "' >") +i+ "</option>";
}
Return MSTR;
}
function Datelist (fName) {
var d=new Date ();
var t=document.all[fname+ "_dd"].value== "" d.getdate ():d ocument.all[fname+ "_dd"].value;
D=new Date (document.all[fname+ "_yy"].value+ "/" +document.all[fname+ "_mm"].value+ "/1");
Dstr= "";
for (Var i=1;i<=31;i++) {
D.setdate (i);
if (D.getdate ()!=i) {break;}
dstr=dstr+ "<option value= '" +i+ (i==t "' selected>": "' >") +i+ "</option>";
}
Document.all[fname+ "_dx"].innerhtml= "<select name= '" +fname+ "_dd ' onchange= ' javascript:setdatevalue ' (/" "+fName+ "/");' > "+dstr+" </select>;
}
function Setdatevalue (name) {
var dvalue=document.all[name+ "_yy"].value+ "-" +document.all[name+ "_mm"].value+ "-" +document.all[name+ "_dd"].value " ;
Document.all[name].value=dvalue;
}
function Showdateselect (name) {
document.write ("<select name= '" +name+ "_yy ' onchange= ' javascript:datelist '" +name+ "/"); Setdatevalue (/"" +name+ "/");' > "+yearlist (+) +" </select> ");
document.write ("<select name= '" +name+ "_mm ' onchange= ' javascript:datelist '" +name+ "/"); Setdatevalue (/"" +name+ "/");' > "+monthlist () +" </select> ");
document.write ("<span id= '" +name+ "_dx ' ><select name= '" +name+ "_dd ' >" + "</select></span>");
Datelist (name);
document.write ("<input type= ' hidden ' name= '" +name+ "' value= '" > ");
Setdatevalue (name);
}
-->
</script>

<body>
<center> <table align= "center" Width= "cellspacing=" "1" cellpadding= "5" Border
<form method=post action= "onsubmit=" alert (' Date1: ' + This.date1.value+ '/ndate2: ' +this.date2.value+ '/ndate3: ' +this.date3.value '; return false;
 
<tr>
 <td> date 1: <script language= "JavaScript" >showdateselect ("Date1") ; </script></td>
</tr>
<tr>
 <td> date 2: <script language= "JavaScript ">showdateselect (" Date2 "); </script></td>
</tr>
<tr>
 <td> Date 3: <script language= "JavaScript" >showdateselect ("Date3"); </script></td>
</tr>
<tr
 <td><center><input type= "Submit" value= "submit" ></CENTER></TD>
</tr>
</form>
</table>
</body>

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.