0

hi guys, i am trying to populate a listbox the number of the current month in listbox. and i am using an onload event of the body but it doesnt works. any help please?. i am new on javascript.

function dat(){
         
                var date=new Date();
                var Month= toString(date.getMonth()+1)
                this.Monthlistbox.options=new Option(Month,Month,true,true);

<body onLoad="dat()">
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by mahavir123
0
<script type="text/javascript">
function dat()
{
	var date=new Date();
	var Month= date.getMonth()+1;
	var opt = document.createElement("option");
	document.getElementById("Monthlistbox").options.add(opt);
	//document.body.Monthlistbox.option.add(opt);
	opt.name = 'month';
	opt.value = Month;
	opt.text = Month; alert(opt.text)
}
</script>
<body onLoad="dat()">
<select name="Monthlistbox" id="Monthlistbox">
</select>
</body>

Try it

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.