User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 423,539 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,277 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1413 | Replies: 2
Reply
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 173
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Date function in Drop-Down Box

  #1  
Mar 2nd, 2008
  1. <select name="test1" style="width: 200px">
  2. <option></option>
  3. </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.
"I might not be the BEST but I'm not like the REST!"
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 146
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 15
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Solution Re: Date function in Drop-Down Box

  #2  
Mar 2nd, 2008
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
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote  
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 173
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Re: Date function in Drop-Down Box

  #3  
Mar 3rd, 2008
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.
Last edited by lordx78 : Mar 3rd, 2008 at 5:34 am.
"I might not be the BEST but I'm not like the REST!"
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 5:34 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC