<select name="test1" style="width: 200px">
<option></option>
</select>

This is typical drop-down box in html forms. My question is, hot to make the option to capture current date. Or Must I use any other function than drop-down box.

Please advise.

Hi there,

try this code("Function") this may help you

JavaScript:

<script type="text/javascript">
//<![CDATA[
<!--
function addDate(){
	var d=new Date();
	var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
	var	selectBox = document.getElementById("test1");
	var optn = document.createElement("OPTION");
	optn.text = TODAY;
	optn.value =  TODAY;
	selectBox.options.add(optn);
}
//-->
//]]>
</script>

HTML

<a href="javascript:void(0);"	onclick="addDate()">create Option</a>
<select name="test1" style="width: 200px" id="test1">
<option>Select Date</option>
</select>

But if you like to to capture current date, then you can use Text Box, i think there is not any need of multiple selections for current date...

Function for Text Box
JavaScript:

<script type="text/javascript">
//<![CDATA[
<!--
function addDate(){
	var d=new Date();
	var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
	/***** TextBox *****/
	var	TextBox = document.getElementById("TextBox");
	TextBox.value = TODAY;
	/************/
}
//-->
//]]>
</script>

HTML

<a href="javascript:void(0);"	onclick="addDate()">create Option</a>
<input name="TextBox" type="text" id="TextBox">

I Hope this will help you


Best Regards,
Rahul Dev Katarey

Thanks for the codes. Actually I'm looking for the codes which can produce output like this

2000-03-24(masked)

The date should be in that particular format and masked. Once the form is open, the current date will be automatically there and masked.

advise pls.

This article has been dead for over six months. Start a new discussion instead.