OnTextChanged Event Not firing

I have a situation where when a textbox OnTextChange event fires, a javascript function is supposed to calculate age.  It works fine when I do a postback, however I want it to change without doing a postback.  I thought that was the point of putting the javascript function clientside.  I have other javascript that works fine without needing to register the code.  I did not use the AJAX update panel because I do not want to do a postback to execute the code.  The age should be calculated when the textbox looses focus.  I am using Visual Studio 2008, C# and .NET 3.5.  My code is below.
Clientside code:
        function calcDiff() 
        {
            var BDate = document.getElementById("txtBirthdate");
            var ODate = document.getElementById("txtOnsetDate");
            var Disease = document.getElementById("lbDisease");
            var CDCYear = document.getElementById("lbcdcyear");
 
            if ((BDate !== null) && (ODate !== null) && !(Disease == "Lead(child blood)" || Disease == "Hepatitis B, chronic" || Disease == "Hepatitis C, chronic") && parseInt(CDCYear) >= 2009) {
                var years = ODate.getFullYear() - BDate.getFullYear();
                var mos = ODate.getFullMonth() - BDate.getFullMonth();
                document.getElementById("lbAgeCalc").value = "1";
                if (years >= 1) {
                    document.getElementById("txtAge").value = years;
                    document.getElementById("txtAgeMos").value = "";
                    document.getElementById("txtAgeMos").style.backgroundColor = "#ece9d8";
                    document.getElementById("txtAgeMos").disabed = "true";
                    document.getElementById("txtAge").style.backgroundColor = "#ece9d8";
                    document.getElementById("txtAge").disabed = "true";
                }
                else {
                    document.getElementById("txtAgeMos").value = mos;
                    document.getElementById("txtAge").value = "";
                    document.getElementById("txtAge").style.backgroundColor = "#ece9d8";
                    document.getElementById("txtAge").disabed = "true";
                    document.getElementById("txtAgeMos").style.backgroundColor = "#ece9d8";
                    document.getElementById("txtAgeMos").disabed = "true";
                }
            }
            else {
                document.getElementById("txtAge").disabed = "false";
                document.getElementById("txtAgeMos").disabed = "false";
                document.getElementById("txtAge").value = "";
                document.getElementById("txtAgeMos").value = "";
                document.getElementById("lbAgeCalc").value = "0";
            }
            document.all.dvFloatMsg.style.display = "inline";
            document.all.lblMsgDataChanged.style.display = "inline";
            document.all.lblMsgDataSaved.style.display = "none";
            document.all.dvFloatMsg.style.pixelLeft = tbMasterTable.offsetLeft + tbMasterTable.offsetWidth - dvFloatMsg.offsetWidth;
            document.all.dvFloatMsg.style.pixelTop = document.all.dvFloatMenu.style.pixelTop + dvFloatMenu.offsetHeight + 5;
            document.all.lbChangedInfo.style.visibility = "visible";
            document.all.lbSavedInfo.style.visibility = "hidden";
        }
<asp:TextBox ID="txtBirthdate" runat="server" MaxLength="10" Width="90px" CssClass="ObservationText" AutoPostBack="false"></asp:TextBox>
<asp:TextBox ID="txtOnsetDate" runat="server" MaxLength="10" Width="110px" CssClass="ObservationText" AutoPostBack="false"></asp:TextBox>
 
Serverside Code:
 
protected void Page_Load(object sender, System.EventArgs e)
{
   //Lots of other code
  // relevent code
              this.txtBirthdate.Attributes.Add("OnTextChanged", "javascript:calcDiff();");
            this.txtOnsetDate.Attributes.Add("OnTextChanged", "javascript:calcDiff();");
// lots more code
}

Open in new window

LVL 1
RosalindPAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guru_samiCommented:
use "onblur" instead "OnTextChanged"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RosalindPAuthor Commented:
There isn't an OnBlur event for textboxes in DTD XHTML 1.0 Transitional.
0
guru_samiCommented:
OnBlur is not an event for asp.net TB Control...but your asp.net contol will be finally rendered to HTML.
onblur is an HTML TB control attibute...
Try the following example and see:

<script language='javascript' type='text/javascript'>
        function display() {
            var tb1 = document.getElementById('<%=TextBox1.ClientID%>').value;
            var tb2 = document.getElementById('<%=TextBox2.ClientID%>');
            tb2.value = tb1;
            return false;
        }
</script><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

TextBox1.Attributes.Add("onblur", "javascript:return display();");
0
RosalindPAuthor Commented:
Thank you.  Your explanation was very clear and now I have a better understanding of how the process works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.