Javascript error

They have: 38 posts

Joined: Dec 2002

I found a script that when a form is processed prints out the date/time:

<script language="JavaScript">
0) ? nd.getYear().substr(2,2) : nd.getYear();
var mins = nd.getMinutes();
var hours = (nd.getHours() > 12) ? nd.getHours() - 12 : nd.getHours();
var pmam = (nd.getHours() > 12) ? "pm" : "am";
var newdate = month + "/" + day + "/" + year + " " + hours + ":" + mins + pmam;
document.Contact.Date.value = newdate;
}
//-->
</script>

It prints everything out perfectly except for the time. it doesnt seem to want to print "0"
Example:
3:6 Instead of 3:06

Please help!

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Change this line

var mins = nd.getMinutes();'

to

var mins = (nd.getMinutes() < 10) ? "0" + nd.getMinutes() : nd.getMinutes();'

That simply adds a "0" ahead of the minute, if the minute is under 10.

Wink

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.