Date function in Drop-Down Box

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Oct 2007
Posts: 178
Reputation: lordx78 is an unknown quantity at this point 
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Date function in Drop-Down Box

 
0
  #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!"
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 154
Reputation: katarey is an unknown quantity at this point 
Solved Threads: 20
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Re: Date function in Drop-Down Box

 
0
  #2
Mar 2nd, 2008
Hi there,

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

JavaScript:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. //<![CDATA[
  3. <!--
  4. function addDate(){
  5. var d=new Date();
  6. var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
  7. var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
  8. var selectBox = document.getElementById("test1");
  9. var optn = document.createElement("OPTION");
  10. optn.text = TODAY;
  11. optn.value = TODAY;
  12. selectBox.options.add(optn);
  13. }
  14. //-->
  15. //]]>
  16. </script>

HTML
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a href="javascript:void(0);" onclick="addDate()">create Option</a>
  2. <select name="test1" style="width: 200px" id="test1">
  3. <option>Select Date</option>
  4. </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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. //<![CDATA[
  3. <!--
  4. function addDate(){
  5. var d=new Date();
  6. var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
  7. var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
  8. /***** TextBox *****/
  9. var TextBox = document.getElementById("TextBox");
  10. TextBox.value = TODAY;
  11. /************/
  12. }
  13. //-->
  14. //]]>
  15. </script>
HTML
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a href="javascript:void(0);" onclick="addDate()">create Option</a>
  2. <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 Quick reply to this message  
Join Date: Oct 2007
Posts: 178
Reputation: lordx78 is an unknown quantity at this point 
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Re: Date function in Drop-Down Box

 
0
  #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 6:34 am.
"I might not be the BEST but I'm not like the REST!"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC