Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    Date in text field

    Hi friends.
    How can I display the date in a text field?? I need the date in mm/dd/yy format. Thanks
    Tracy

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    try this:
    Code:
    <!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>

  • #3
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts
    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>

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Code:
    <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>

  • #5
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts
    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>

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because the form and date input have not yet been written to the page...
    Move the script below the input and it should work....


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •