Javascript Currency Mask for Asp.Net

My page has a textbox that uses a javascript currency mask function, the mask works fine. TextBox AutoPostBack property is enabled, but the only key that calls the "PostBack" to start the "onTextChanged" event is the "Enter".  I need to call the "PostBack/onTextChanged" when the field loose it's focus (not only pressing "Enter" but for example with "Tab" or simply clicking out). I tried to remove the mask, and everything worked. I don't know if the problem is the script function or the page behavior.
 The textbox used The currency function used
LVL 3
tbsolutionsAsked:
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.

leakim971PluritechnicianCommented:
Remove the return false at the end of the MascaraMoeda function
0
tbsolutionsAuthor Commented:
The textbox keeps responding only when you press "Enter".
0
leakim971PluritechnicianCommented:
Sorry, remove the return in onkeypress too
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

leakim971PluritechnicianCommented:
Like this :


<asp:TextBox ID="txtValorStrike" onkeypress="MascaraMoeda(this,'.',',',event)" CssClass="TextBoxCommon" runat="server" Width="134px" AutoPostBack="True" OnTextChanged="txtValorStrike_TextChanged"></asp:TextBox>

Open in new window

0
leakim971PluritechnicianCommented:
Test page :


<%@ Page Title="Page d'accueil" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script language="javascript" type="text/javascript">

    window.onload = function () {
        alert("alert or postback occured!");
    }

    function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e) {
        var sep = 0;
        var key = '';
        var i = j = 0;
        var len = len2 = 0;
        var strCheck = '0123456789';
        var aux = aux2 = '';
        var whichCode = (window.Event) ? e.which : e.keyCode;
        if(whichCode ==13) return true;
        key = String.fromCharCode(whichCode);
        if(strCheck.indexOf(key) == -1) return false;
        len = objTextBox.value.length;
        for(i=0;i<len;i++)
            if(strCheck.indexOf(objTextBox.value.charAt(i)) != -1 ) aux += objTextBox.value.charAt(i);
        aux = '';
        for(;i<len;i++)
            if(strCheck.indexOf(objTextBox.value.charAt(i)) != -1) aux += objTextBox.value.charAt(i);
        aux += key;
        len = aux.length;
        if(len==0) objTextBox.value = '';
        if(len==1) objTextBox.value = '0' + SeparadorDecimal + '0' + aux;;
        if(len==2) objTextBox.value = '0' + SeparadorDecimal + aux;
        if(len==3) objTextBox.value = '0' + SeparadorDecimal + aux;
        if(len==4) objTextBox.value = '0' + SeparadorDecimal + aux;
        if(len>4) {
            aux = '';
            for(j=0,i=len-5;i>=0;i--) {
                if(j==3) {
                    aux2 += SeparadorMilesimo;
                    j=0;
                }
                aux2 += aux.charAt(i);
                j++;
            }
            objTextBox.value = '';
            len2 = aux.length;
            for(i=len2-2;i>=0;i--) {
                objTextBox.value += aux2.charAt(i);
            }
            objTextBox.value += SeparadorDecimal + aux.substr(len-4, len);
         }
         //return false;
    }

</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:TextBox ID="txtValorStrike" onkeypress="MascaraMoeda(this,'.',',',event)" CssClass="TextBoxCommon" runat="server" Width="134px" AutoPostBack="True" OnTextChanged="txtValorStrike_TextChanged"></asp:TextBox>
</asp:Content>

Open in new window

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
tbsolutionsAuthor Commented:
That's it! Thanks.
0
leakim971PluritechnicianCommented:
You're welcome! Thanks for the points!
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
ASP.NET

From novice to tech pro — start learning today.