|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Other - Adding AM/PM to a form submittal |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|