Thursday 29 December 2016

get month number from month name using javascript

get month number from month name using javascript

Introduction:

Here I will explain how to get month number from month name using javascript. In javascript such a not inbuilt function to get month number from month name so I have create this smaal function to get month number from month name using javascript. It is easiest way to convert month name to month number in javascript.

In previous post I explained System.Array' does not contain a definition for 'Count' how to access session in class c# how to create chat application in asp.net using c# sql query to get daily count and many article about Asp.net javascript and C#

Search:

how to get month number from month name using Javascript
get month number from month name


Eample:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>get month number from month name using javascript</title>
    <script>
        function getMonthFromName(MonthName) {
            var Month = 1;
            switch (MonthName) {
                case "January":
                    Month = 1;
                    break;
                case "February":
                    Month = 2;
                    break;
                case "March":
                    Month = 3;
                    break;
                case "April":
                    Month = 4;
                    break;
                case "May":
                    Month = 5;
                    break;
                case "June":
                    Month = 6;
                    break;
                case "July":
                    Month = 7;
                    break;
                case "August":
                    Month = 8;
                    break;
                case "September":
                    Month = 9;
                    break;
                case "October":
                    Month = 10;
                    break;
                case "November":
                    Month = 11;
                    break;
                case "December":
                    Month = 12;
                    break;
            }
            return Month;
        }
        function getMonthNumber() {
            var MonthNo = getMonthFromName(document.getElementById('txtMonthName').value);
            document.getElementById('lblMonthNumber').innerHTML = MonthNo.toString();
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <h1>get month number from month name using javascript</h1>
            <input type="text" id="txtMonthName" />
            <input type="button" value="Get Month Number" onclick="getMonthNumber();" />
            <br />
            Month Number is:
            <label ID="lblMonthNumber"></label>
        </div>
    </form>
</body>
</html>

You might also like

1. file type validation in jquery
2. file size validation in jquery
3. calling web service without adding web reference
4. How to bind CheckBoxList from database
5. How to bind DropdownList from database

No comments:

Post a Comment



Asp.net tutorials