Dwalker said:
I just want to enter today's date in a text input box with the format
mm/dd/yyyy when it receives focus. I've been playing around with this but
just can't seem to get it to work.
<html>
<head>
<script type="text/javascript">
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>
</head>
<body>
<form>
<input onfocus="insertDate(this,'MM/DD/YYYY')"><br>
<input onfocus="insertDate(this,'MM/DD/YY')"><br>
<input onfocus="insertDate(this,'DD/MM')"><br>
<input onfocus="insertDate(this,'YYYY-MM-DD')"><br>
</form>
</body>
</html>