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()">
<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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.