Erfan Ahmed Emon Erfan Ahmed Emon - 11 months ago 29
Javascript Question

Dynamic selection of HTML select tag in laravel5.0

Let's have a select tag of months of a year

<label name="month">Select Month</label>
<select class="form-control">

How can I set the current month number dynamically ? e.g. If it is May then '5' will be selected automatically. However user can also select a month manually with the help of drop down option.I want to use it in my laravel5.0 application.


Basically, you need use JavaScript getMonth() Method.

If you do not use JQuery, try

var date = new Date();
var month = date.getMonth + 1
document.getElementByClass("form-control").value = month;

Thanks for the comment of Erfan, we need +1 for the value of month.

Note: In getMonth(), 0=January, 1=February etc.