JavaScript Script working in IE not FF
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Script working in IE not FF

  1. #1
    Join Date
    Sep 2004
    Posts
    12

    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

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,880

    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.

  3. #3
    Join Date
    Sep 2004
    Posts
    12

    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.

  4. #4
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,880

    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.

  5. #5
    Join Date
    Sep 2004
    Posts
    12

    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.

  6. #6
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,880

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center