It works for any browser because the format of a bad date is decided by the browser interpreting the JavaScript, not the programmer.
<script>
function validateDate(tb) {
var datestring = (new Date(tb.value)).toString();
if(datestring == (new Date("bad date")).toString()) {
// bad date code e.g.
alert("bad date!");
tb.select();tb.focus();
} else {
// good date code
// Need to feed the result back to the TB because it might have a different result than expected.
// for instance, a common mistake is to enter 9/31/2007 for the end of the FY - but September only has 30 days
// so we feed it back so they see that JS Date object interpreted it as the next day: October 1.
tb.value = datestring;
// or
tb.value = (date.getMonth()+1)+"/"+date.getDate()+"/"+date.getFullYear();
}
}
</script>
<input type="text" onchange="validateDate(this)" >
Basic Event handling that works across "every" browser.
Largely undocumented, there is an implicit object named "event" passed to in-line event handlers in most non-IE browsers,
and in IE the word event will refer to the window.event object,
thus you get a handle to the event object in almost any browser using this technique.
The members of the object vary, but a few items are supported in most all browsers:
screenX/screenY
type
<input onevent="handleEvent(event)" >
<script>
function handleEvent(e) {
}
</script>
Test Mouseover Event
Basic DHTML that works across "every" browser.
//DHTML
function _getElementById(id) {
if(document.layers) {
var item = document.layers[id];
item.style = item;
return item;
} else {
return document.all[id];
}
}
if(!(document.getElementById) {
document.getElementById = _getElementById;
}
//the works in Netscape 4 (if testid is absolutely positioned), Mozilla, Firefox, and IE 5, 6, and up.
var test = document.getElementById("testid");
//the following can be assigned in Netscape 4, Mozilla, Firefox, and IE 5, 6, and up.
test.style.left;
test.style.top;
test.style.zIndex;
test.style.visibility;
// That is enough to perform just about any DHTML -
// just have multiple renderings, and hide and show and position them as needed.