April 21st, 2012 11:30 AM
#1
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);" />
Last edited by PeejAvery; April 21st, 2012 at 11:55 AM .
Reason: Added code tags
April 21st, 2012 11:57 AM
#2
Re: Script working in IE not FF
Did you check the Firefox Error Console before posting?
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
April 21st, 2012 12:31 PM
#3
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.
April 21st, 2012 12:49 PM
#4
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
April 21st, 2012 01:26 PM
#5
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.
April 23rd, 2012 01:45 AM
#6
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks