Web Analytics Made Easy -
StatCounter Date to a text box - CodingForum

Announcement

Collapse
No announcement yet.

Date to a text box

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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>

    Comment


    • #3
      Thanks... that worked great.

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

      Comment


      • #4
        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; Jun 20, 2002, 08:32 PM.
        Former ASP Forum Moderator - I'm back!

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

        Comment

        Working...
        X