|dateObject.setMonth( month ,day );|
Where month is a number between 0 to 11 and its representations are as follows :
|Month Number||Represents Month|
The parameter day is optional and consists a numerical value between 1 to 31 that represents the day. Note that we must need to have a date object to call this method.
Description of code :
To illustrate the use of setMonth() method we have created a simple html page and in this page we have provided a text box. User can enter month number here. We also have suggested that user must input the month number between 0 to11. If user enters any thing else than valid month number between 0 to 11 then it shows "Invalid month number" message into alert method.
When user clicks on the button "Set Month" after inserting month it checks that whether month number provided is valid or not. Here is the full example code :
Input valid month number to set into setMonth() method.
If user enters any thing else than a valid month number then it will show message "Invalid month number" into an alert message. For example if we enter Jan, Feb or any thing other than a number between 0 to 11 then it shows an alert message.
If we enter "12" and click on the button "Set Month",
date before calling setMonth() method will be look like this
Date after calling the method setMonth() would look like as follows :
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: February 7, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles