JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 12th, 2007, 02:33 PM
jmuia3377 jmuia3377 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 1 jmuia3377 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 27 sec
Reputation Power: 0
Other - Adding AM/PM to a form submittal

I'm trying to add AM/PM to the submission of my form. I basically want this form timestamped when the person fills out the other related data in the field.

I have everything working fine except for the AM/PM part. I just don't know enough about Javascript to implement the code properly.

Below is what I currently have working.

<form method="post" onsubmit="return false;">
<input type="hidden" name="submitted_date" value="">
<!-- rest of your form -->
<input type="submit" onClick="addDate(this.form);" value="submit">
</form>

<script type="text/javascript">
function addDate(form) {
var day = new Date();
var submitted = (day.getMonth()+1)+'/'+day.getDay()+'/'+day.getYear()+' '+day.getHours()+':'+day.getMinutes()+':'+day.getS econds();
form.submitted_date.value=submitted;
form.submit();
}
</script>


I don't know how to implement a correct AM/PM code into what I have. Below is some code I found off the net but its for timestamping a page, and I'm sure the code needs to change a bit.

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
Stamp = new Date();
document.write('<font size="3"><B>' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getYear() + '</B></font><BR>');
var Hours;
var Mins;
var Time;
Hours = Stamp.getHours();
if (Hours >= 12) {
Time = " P.M.";
}
else {
Time = " A.M.";
}
if (Hours > 12) {
Hours -= 12;
}
if (Hours == 0) {
Hours = 12;
}
Mins = Stamp.getMinutes();
if (Mins < 10) {
Mins = "0" + Mins;
}
document.write('<font size="3"><B>' + Hours + ":" + Mins + Time + '</B></font>');
// End -->
</SCRIPT>

or

<script type="text/javascript">
<!--
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10)
minutes = "0" + minutes
document.write(hours + ":" + minutes + " ")
if(hours > 11){
document.write("PM")
} else {
document.write("AM")
}
//-->
</script>


Any idea's how implement this into my form submission?

Thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Other - Adding AM/PM to a form submittal


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
Stay green...Green IT