Script working in IE not FF
Not a JS guru, so can someone tell me why the following works on a .net aspx page in Javascript for IE, but no FF?
Code:
getAge = function(form) {
document.getElementById('txtDOB').value = ((document.getElementById('txtDOB').value).replace(new RegExp("/", "g"), "-"));
var now = new Date();
var DOB = new Date(document.getElementById('txtDOB').value);
var oneDay = 1000 * 60 * 60 * 24 * 365; //converts from milliseconds
document.getElementById('txtAge').value = parseInt((now.getTime() - DOB.getTime()) / oneDay);
}
<asp:TextBox ID="txtDOB" runat="server" onkeyup="javascript:getAge(this.form);" onkeydown="javascript:getAge(this.form);" />
Re: Script working in IE not FF
Did you check the Firefox Error Console before posting?
Re: Script working in IE not FF
Yes, nothing. It changes the "/" to "-", but doesn't compute the age. Works fine in IE. BTW - I'm using FF11 if it matters.
Re: Script working in IE not FF
I would guess that the issue is the regexp. Alert document.getElementById('txtDOB').value right after the regexp line.
See what result that gives you for both browsers.
Re: Script working in IE not FF
I changed it to onBlur cause the alerts drove me nuts. In both cases, I got "1-21-1978". The difference being that the IE then calculates the age and the FF does not.
Re: Script working in IE not FF
Well...I tried the function and it worked for me in both. Put alerts after each line and see where it fails for you.