Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add todays date to field when other field is changed

Status
Not open for further replies.

amillia

Programmer
Nov 14, 2001
124
0
0
US
I have a cHTML page with a date field called obj_lmt_dte which I need to insert todays date and time into when the a field called obj_lmt is entered. The format for the date field I need is 5/5/2007 1:02:03 PM. I am trying to build the script myself but I don't know javascipt too well so any help would be appreciated.
 
I'll start you off by giving you a prototype that returns the date in the format you want:

Code:
<script type="text/javascript">
Date.prototype.fullDateTime = function() {
   if (this.getHours() < 12) {
      var amPm = "AM"
   }
   else {
      var amPm = "PM"
   }
   if (this.getHours() == 0) {
      var theHours = 12;
   }
   else if (this.getHours() < 12) {
      var theHours = this.getHours();
   }
   else {
      var theHours = this.getHours() - 12;
   }
   var buildString = this.getMonth() + 1 + "/" + this.getDate() + "/" + this.getFullYear();
   buildString += " " + theHours + ":" +  this.getMinutes() + ":" + this.getSeconds() + " " + amPm;
   return buildString;
}
</script>

This prototype can be called like so:
Code:
var now = new Date();
alert(now.fullDateTime());

All you have to do is run a function call when the field obj_lmt is changed. The only thing that function has to do is set the obj_lmt_dte field = now.fullDateTime().

At least give it a try.



[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
Thank you very much for your help. I changed the code a little because what I realized I really needed to do was set the field in the asp page when the record set was pulled. Here is the jest of the code.

<script type="text/javascript">
var now = new Date();
function putDate(now) {
if (now.getHours() < 12) {
var amPm = "AM"
}
else {
var amPm = "PM"
}
if (now.getHours() == 0) {
var theHours = 12;
}
else if (now.getHours() < 12) {
var theHours = now.getHours();
}
else {
var theHours = now.getHours() - 12;
}
var buildString = now.getMonth() + 1 + "/" + now.getDate() + "/" + now.getFullYear();
buildString += " " + theHours + ":" + now.getMinutes() + ":" + now.getSeconds() + " " + amPm;
return buildString;
}
</script>

<script language="VBScript" >

document.all.item("OBJ_ltm_date").value = "buildString"



</script>

Since I changed the javascript I can't tell if I changed it correctly and I am sure that I am not setting the field right. I will keep trying. Thank you for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top