Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old January 11th, 2008, 11:52 AM
bryceowen bryceowen is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 57 bryceowen User rank is Sergeant (500 - 2000 Reputation Level)bryceowen User rank is Sergeant (500 - 2000 Reputation Level)bryceowen User rank is Sergeant (500 - 2000 Reputation Level)bryceowen User rank is Sergeant (500 - 2000 Reputation Level)bryceowen User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 8 h 27 m 52 sec
Reputation Power: 6
Insert current time into a form field

I spent quite a while looking for something like this and finally managed to piece it together, using bits of code here and there. I'm still learning this, so it might not be that impressive to some, but I'm sure someone will find it useful.

Code:
<script language="JavaScript" type="text/JavaScript">
function inserttime(time)
	{
	var d = new Date();

	var curr_hour = d.getHours();
	var curr_min = d.getMinutes();

	curr_hour = checkTime(curr_hour);
	curr_min = checkTime(curr_min);

	time.value = curr_hour + ":" + curr_min
	}

function checkTime(i)
	{
	if (i < 10)
		{
		i = "0" + i;
		}
	return i;
	}
</script>


Then simply call it with onClick="inserttime(document.{form name}.{field name}). This particular code assumes 24-hour display.

Edit: Had to move the hour/min check outside the "inserttime" function in order for it to work correctly.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Insert current time into a form field


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway