Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 14th, 2006, 01:29 PM
Registered User
 
Join Date: Oct 2006
Location: Delhi, Delhi, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ramesh055 Send a message via MSN to ramesh055 Send a message via Yahoo to ramesh055
Default Date Validation

sir/madam,

I have a problem with datatime.
I drag 3 DropDownList in some aspx page and add items as month, days and year in the respective DropDownList.
Now i want to add numbers in days_DDL according to the no. of days the particular month have.eg- when user select February from month DropDownList then month_DDL should display only upto 28 days so that user cannot enter INVALID date as 30 Feb 2000 or something like that.
So i want valid date from user in the above prescribed manner.

can i write javascript for that so when user select the page does not go back to the server and take the immediate effect without flashback.

so please help to solve the problem..... and if possible with some code also.....

Thanks
 
Old November 15th, 2006, 11:09 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi

You can simply copy and paste the code below in notepad, save it as htm to see the result, but remember, I have not written the code here to validate leap year, that's the task for you.

<HTML><HEAD><TITLE>monthdays</TITLE>

<SCRIPT>
            function FillDays(ID)
            {
                switch(ID)
                {
                    case "1":AddDays("31"); break;case "2":AddDays("28");break;case "3":AddDays("31");break;
                    case "4":AddDays("30");break;case "5":AddDays("31");break;case "6":AddDays("30");break;
                    case "7":AddDays("31");break;case "8":AddDays("31");break;case "9":AddDays("30");break;
                    case "10":AddDays("31");break;case "11":AddDays("30");break;case "12":AddDays("31");break;
                }
            }

            function AddDays(Total)
            {

                //Add items
                for (var j = 1; j <= Total; j ++)
                {
                    //Set text and value fields of dropdown
                    var optn = document.createElement("OPTION");
                    optn.text = j;
                    optn.value = j;

                    //Add items
                    document.getElementById("lstDays").options.add(opt n);

                }
            }
        </SCRIPT>
</HEAD>
<BODY>
 <SELECT
id=lstMonth onchange=FillDays(this.value)> <OPTION value=0
  selected>Select</OPTION> <OPTION value=1>Jan</OPTION> <OPTION
  value=2>Feb</OPTION> <OPTION value=3>Mar</OPTION> <OPTION value=4>Apr</OPTION>
  <OPTION value=5>May</OPTION> <OPTION value=6>Jun</OPTION> <OPTION
  value=7>Jul</OPTION> <OPTION value=8>Aug</OPTION> <OPTION value=9>Sep</OPTION>
  <OPTION value=10>Oct</OPTION> <OPTION value=11>Nov</OPTION> <OPTION
  value=12>Dec</OPTION></SELECT> <SELECT id=lstDays></SELECT>
</BODY></HTML>


Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Validation aftabn10 PHP How-To 0 January 29th, 2007 10:35 AM
Date validation vacak Struts 0 November 21st, 2006 12:11 PM
date validation (again) crmpicco Javascript How-To 14 March 29th, 2006 06:58 PM
Date Validation surendran Javascript How-To 3 February 25th, 2005 07:40 AM
Date validation Raul Javascript 4 February 25th, 2004 04:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.