Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi , I am using following Javascript for pending ammount calculation, and call on payammount text box on

<asp:TextBox ID="txtpayAmmount" runat="server" MaxLength="7" onfocus="myFunction1()" onfocusout="myFunction()">

but When I click on update button on click event of updatebtn pending ammount textbox gives privious value.

but actually it should be new value which is present in textbox




XML
<script language="javascript" type="text/javascript">
        var i = parseInt("1");
        var t4;
        var t5;
        var c1 = 0;

        function myFunction() {

            // Created By Amol
            var t1 = document.getElementById('<%= txtPendingAmmount.ClientID %>').value;
            var t2 = document.getElementById('<%= TxtTotalAmmount.ClientID %>').value;
            var t3 = document.getElementById('<%= txtpayAmmount.ClientID %>').value;
            // Check if value pay ammount is not greater than pending Ammount
            if (parseInt(t3) > parseInt(t1)) {
                alert("invalid Ammount"); document.getElementById('<%= txtpayAmmount.ClientID %>').value = t1;
                document.getElementById('<%= txtPendingAmmount.ClientID %>').value = c1;
            }
            else {
                var t9 = t1 - t3;
                //var t10 = t2 - t3;

                document.getElementById('<%= txtPendingAmmount.ClientID %>').value = t9;


            }
        }
        function myFunction1() {

            if (i === 1) {

                t4 = document.getElementById('<%= txtPendingAmmount.ClientID %>').value;


            }

            if (i > 1) {
                document.getElementById('<%= txtPendingAmmount.ClientID %>').value = t4;

            }

            i = i + 1;
        }
</script>






please tell me urgent ................
thanks in advance...
Posted

1 solution

I checked your scenario with a simple example using jQuery as below:-

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script>
        // on focus out
        function myFunction() {
            $('#txtpayAmmount').val(3);
        }

        // on focus
        function myFunction1() {
            $('#txtpayAmmount').val(2);
        }
    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:textbox id="txtpayAmmount" runat="server" maxlength="7" onfocus="myFunction1()" onfocusout="myFunction()" text="1" xmlns:asp="#unknown"></asp:textbox>
            <asp:button id="btnTest" runat="server" text="Test" onclick="btnTest_Click" xmlns:asp="#unknown" />
    </div>
    </form>
</body>
</html>


On server side button click event handler i got the value for the textbox which ever is set onfocusout i.e 3.

Hope this will be of help to you.
 
Share this answer
 
v2
Comments
Shrikesh_kale 22-Jul-15 7:33am    
Thanks It working..............
SRS(The Coder) 22-Jul-15 7:41am    
always wl cm...:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900