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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2002
    Location
    NY, NY
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Date to a text box

    I am trying to figure out a way that when a page loads it pulls the date and time into a text box.

    Any ideas....

    Thanks

  • #2
    New to the CF scene
    Join Date
    Jun 2002
    Location
    Farmington Hills, MI
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Super simplified version:


    <head>

    function plugTime(){

    t = new Date()

    //format how you like

    document.form1.timeField.value = t
    }


    </head>



    <body onload = "plugTime()">
    ...
    <form name = 'form1'>
    <input type="text" name = "timeField" value ="">
    </form>
    ...
    </script>

  • #3
    New to the CF scene
    Join Date
    Jun 2002
    Location
    NY, NY
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks... that worked great.

    How can I format it to mm/dd/yy??????

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Play with this...

    Code:
    <form name="myform">
    <table border="0" cellpadding="0" cellspacing="0">
    	<tr>
    		<td>	<input	type="text" 
    				name="thedate" 
    				size="11" 
    				maxlength="10" 
    				style="background:#cccccc; color:#000000; border style:1px solid #666666; text-align:center; font-weight:normal; font-size:12px" 
    			>
    			</input>
    		</td>
    	</tr>
    	<tr>
    		<td>	<input	type="text" 
    				name="time" 
    				size="11" 
    				maxlength="11" 
    				style="background:#cccccc; color:#000000; border style:1px solid #666666; text-align:center; font-weight:normal; font-size:12px"
    			>
    			</input>
    		</td>
    	</tr>
    </table>
    </form>
    
    <script language="javascript">
    <!--
    function showdate(){
    	var thedate=new Date();
    	var mymonth=thedate.getMonth()+1;
    	var mydate=thedate.getDate();
    	var myyear=thedate.getFullYear();
    		if(mymonth<10){
    			mymonth="0"+mymonth;
    		}
    		if(mydate<10){
    			mydate="0"+mydate;
    		}
    	mynewdate=mymonth+"/"+mydate+"/"+myyear;
    	var thefield=document.myform.thedate;
    	thefield.value=mynewdate;
    	thefield.blur();
    	setTimeout("showdate()",1000);
    }
    showdate()
    // -->
    </script>
    
    <script>
    <!--
    function showtime(){
    	var meridian="AM";
    	var mydate=new Date();
    	var myhours=mydate.getHours();
    	var myminutes=mydate.getMinutes();
    	var myseconds=mydate.getSeconds();
    		if (myhours>11){
    			myhours-=12;
    			meridian="PM";
    		}
    		if(myhours==0){
    			myhours=12;
    		}
    		if(myminutes<10){
    			myminutes="0"+myminutes;
    		}
    		if(myseconds<10){
    			myseconds="0"+myseconds;
    		}
    	mynewtime=myhours+":"+myminutes+":"+myseconds+" "+meridian;
    	var thefield=document.myform.time;
    	thefield.value=mynewtime
    	thefield.blur();
    	setTimeout("showtime()",1000)
    }
    showtime()
    //-->
    </script>
    Last edited by whammy; 06-21-2002 at 01:32 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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