wrote:
> Why won't this work in Firefox:
> document.getElementById('content').focus();
> Is there something else to use?
Advice above is good. If you are going to compare date strings, you
must compose them yourself.
var dtToday = Date()
will create a new date object with a date/time of the instant it was
created according to the settings of the user's local machine. This is
likely not accurate or reliable, so you must validate on the server.
Simply writing dtToday will create some string according to the
settings of the local machine, which could be anything.
Supposing txtDDate is the string "01/24/2005", then the equivalent date
string constructed from dtToday will be given by the script below.
Note that date & month less than "10" need a leading zero and that
getFullYear() is not supported on all browsers, so you may need to use
getYear and deal with it's eccentricities:
<script type="text/javascript">
function checkZero(a){
return (a < 10)? "0" + a : a;
}
function todayDate() {
var dtToday = new Date();
var dtTodayString = checkZero(+dtToday.getMonth()+1)
+ '/' + checkZero(dtToday.getDate())
+ '/' + dtToday.getFullYear();
alert(dtTodayString);
}
</script>
<button onclick="todayDate()">Click me</button>
In regard to date formats, if users' aren't going to see them (or
perhaps even if they are) the accepted international standard is
ISO8601. Your date above would become 2005-01-24 or 2005/01/24. Read
stuff on dates here:
<URL:http://www.merlyn.demon.co.uk/js-dates.htm>
The format mm/dd/yyyy is peculiar to the US and is likely to be
misinterpreted elsewhere in the world. ISO8601 dates should not be.
I appologise for baddly formatted code, but Google Groups insists on
removing all leading spaces, so there's not much I can do.