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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onload need help 1

Status
Not open for further replies.

Killborg

Technical User
Jul 16, 2007
46
US
I am trying to get the date to appear in a text box.
I got it to appear when you select the field.

I have tried changing onfocus to onload. But still does not work Need help

<script type="text/javascript">//This script is for date
function zp(n){
return n<10?("0"+n):n;
}
function insertDate(t,format){
var now=new Date();
var DD=zp(now.getDate());
var MM=zp(now.getMonth()+1);
var YYYY=now.getFullYear();
var YY=zp(now.getFullYear()%100);
format=format.replace(/DD/,DD);
format=format.replace(/MM/,MM);
format=format.replace(/YYYY/,YYYY);
format=format.replace(/YY/,YY);
t.value=format;
}
</script>
<input name="Date" id="Date" onclick="insertDate(this,'MM/DD/YYYY')" />
 
Something like:
Code:
window.onload = "insertDate(document.getElementById('Date'),'MM/DD/YYYY')";

Lee
 
The line, in the script section.
[tt]window.onload = function(){insertDate(document.getElementById('Date'),'MM/DD/YYYY')};[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top