Tri Setia

Tri Setia

  • 961
  • 463
  • 22.5k

KeyUp Function not firing on textbox ASP.NET Web Form

Jun 15 2021 3:21 PM

Hi Guys,, I'm trying to make format currency in Indonesian using javascript but why the textbox not firing when keyboard pressed.if this code running in html working properly, but not in ASP.NET. Anny help could be appriciate.

Currency Format in Javascript

<asp:TextBox ID="txtCurrency" onkeyup ="return(this) FormatRupiah();" runat="server"></asp:TextBox>
<script type="text/javascript" src="<%=Page.ResolveClientUrl("~/Assets/plugins/jquery/jquery.min.js") %>"></script>
    <script type="text/javascript" lang="javascript">
        $(document).ready(function () {
            function FormatRupiah() {
                var input = document.getElementById("<%=txtCurrency.ClientID%>");
                input.addEventListener('keyup', function(e)
                {
                    var number_string = bilangan.replace(/[^,\d]/g, '').toString(),
                    split = number_string.split(','),
                    sisa = split[0].length % 3,
                    rupiah = split[0].substr(0, sisa),
                    ribuan = split[0].substr(sisa).match(/\d{1,3}/gi);

                    if (ribuan) {
                        separator = sisa ? '.' : '';
                        rupiah += separator + ribuan.join('.');
                    }
                    rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
                    return prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : '');
                });
            }
        });
    </script>

Code Bihind

protected void Page_Load(object sender, EventArgs e)
    {
        txtCurrency.Attributes.Add("onkeyup", "FormatRupiah(this)");
    }

 


Answers (3)