nikko50
12-07-2004, 02:30 PM
Hi friends.
How can I display the date in a text field?? I need the date in mm/dd/yy format. Thanks
Tracy
How can I display the date in a text field?? I need the date in mm/dd/yy format. Thanks
Tracy
|
||||
Date in text fieldnikko50 12-07-2004, 02:30 PM Hi friends. How can I display the date in a text field?? I need the date in mm/dd/yy format. Thanks Tracy Brandoe85 12-07-2004, 04:20 PM try this: <!DOCTYPE html PUBLIC "-W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascript"> function curDate() { var now = new Date(); var day = now.getDay(); var date = now.getDate(); var year = now.getFullYear(); var month = now.getMonth(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds(); var days = new Array(); days[0] = "Sunday"; days[1] = "Monday"; days[2] = "Tuesday"; days[3] = "Wednesday"; days[4] = "Thursday"; days[5] = "Friday"; days[6] = "Saturday"; var display = days[day] + " " + (month +1) + "/" + date + "/" + year; document.forms[0].date.value = display; } </script> </head> <body onload="curDate();"> <form action=""> <p><input type="text" size="30" name="date"/></p> </form> </body> </html> nikko50 12-07-2004, 04:45 PM Hi Brandio, I have the script below that works fine except I would like the year as "yy". <script language="Javascript"> var today = new Date() var month = today.getMonth() + 1 var day = today.getDate() var year = today.getFullYear() var s = "/" document.date.forms.value = month + s + day + s + year </script> Brandoe85 12-07-2004, 05:06 PM <script language="Javascript"> function date() { var today = new Date(); var month = today.getMonth() + 1; var day = today.getDate(); var year = today.getFullYear(); var s = "/"; var y = year.toString(); var yy = y.substring(2,4); document.forms[0].date.value = month + s + day + s + yy; } </script> nikko50 12-07-2004, 06:07 PM Hi Brandoe, Why do I get object in null or undefined error with the below script.... <script language="Javascript"> var today = new Date(); var month = today.getMonth() + 1; var day = today.getDate(); var year = today.getFullYear(); var s = "/"; var y = year.toString(); var yy = y.substring(2,4); document.theForm.date.value = month + s + day + s + yy; </script> <form method="POST" name="theForm" > <input type="text" name="date" size="20"> </form> Willy Duitt 12-07-2004, 06:20 PM Because the form and date input have not yet been written to the page... Move the script below the input and it should work.... |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum