1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

How to get DOB value created by javascript using C#?

Discussion in 'C#' started by hkw_9105, Nov 24, 2012.

  1. hkw_9105

    hkw_9105 New Member

    Hi,
    I create 3 drop down lists to store year, month and day but now I don't know how to store them into database.
    As I create the date value with javascript, and now I unable to retrieve the value.Can somebody help me?

    Javascript :
    Code:
     <script type="text/javascript">
            var month = new Array(11);
            month[0] = "Jan";
            month[1] = "Feb";
            month[2] = "Mar";
            month[3] = "Apr";
            month[4] = "May";
            month[5] = "Jun";
            month[6] = "Jul";
            month[7] = "Aug";
            month[8] = "Sep";
            month[9] = "Oct";
            month[10] = "Nov";
            month[11] = "Dec";
            var date = new Date();
            function getYear() {
                var opt = new Option("Year", "Year");
                document.forms[0]["ddlBirthDateYear"].options.add(opt);
                var currentyear = 2012;            
                var i = 0;           
                for (i = 1977; i < currentyear - 3; i++) {
                    var item = new Option(i, i);
                    document.forms[0]["ddlBirthDateYear"].options.add(item);
                }
            }
            function getMonth() {
                var opt = new Option("Month", "Month");
                document.forms[0]["ddlBirthDateMonth"].options.add(opt);
                for (var i = 0; i <= 11; i++) {
                    var item = new Option(month[i], month[i]);
                    document.forms[0]["ddlBirthDateMonth"].options.add(item);
                }
            }
            function getDays() {
                //to clear all the items from ddDay drop down list simply set the length property to 0.
                document.forms[0]["ddlBirthDateDay"].length = 0;            
                if (document.forms[0]["ddlBirthDateYear"].selectedIndex > 0 && document.forms[0]["ddlBirthDateMonth"].selectedIndex > 0) {
                    var yy = document.forms[0]["ddlBirthDateYear"].value;
                    var mm = document.forms[0]["ddlBirthDateMonth"].selectedIndex;
                    // alert(yy + "\n" + mm);
                    switch (mm) {
                        case 1:
                        case 3:
                        case 5:
                        case 7:
                        case 8:
                        case 10:
                        case 12:
                            for (var i = 1; i <= 31; i++) {
                                var item = new Option(i, i);
                                document.forms[0]["ddlBirthDateDay"].options.add(item);
                            }
                            break;
                        case 4:
                        case 6:
                        case 9:
                        case 11:
                            for (var i = 1; i <= 30; i++) {
                                var item = new Option(i, i);
                                document.forms[0]["ddlBirthDateDay"].options.add(item);
                            }
                            break;
                        case 2:
                            //to calculate if the year is a leap year or not.
                            if (yy % 4 == 0) {
                                for (var i = 1; i <= 29; i++) {
                                    var item = new Option(i, i);
                                    document.forms[0]["ddlBirthDateDay"].options.add(item);
                                }
                            }
                            else {
                                for (var i = 1; i <= 28; i++) {
                                    var item = new Option(i, i);
                                    document.forms[0]["ddlBirthDateDay"].options.add(item);
                                }
                            }
                    }
                }
            }
        </script>
    
    HTML :
    Code:
      <div style="float: right; padding-right: 70%;" >                    
                            <asp:DropDownList ID="ddlBirthDateYear" runat="server">       
                            </asp:DropDownList>  
                            &nbsp;
                            <asp:DropDownList ID="ddlBirthDateMonth" runat="server" onChange="getDays()">
                            </asp:DropDownList>
                            &nbsp;
                            <asp:DropDownList ID="ddlBirthDateDay" runat="server">
                                <asp:ListItem Value="Day"></asp:ListItem>
                            </asp:DropDownList>
                        </div>
     
    Last edited by a moderator: Nov 24, 2012

Share This Page