locked
Compare Text Box Values RRS feed

  • Question

  • User-797751191 posted

    Hi

      I have 2 TextBoxes txtAmount1 & txtAmount2. I want to check if both have value > 0 then "Both" should get displayed.

    If txtamount1 > 0 then "1" . If txtamount2 >0 then "2"

    Thanks

    Monday, June 24, 2019 6:25 AM

Answers

  • User-1038772411 posted

    Hello jsshivalik,

    Try with this

    //Checking conditions
    if (txtamount1!=null && !string.IsNullOrWhiteSpace(txtamount1) && txtamount1.Length > 0 && txtamount2!= null && !string.IsNullOrWhiteSpace(txtamount2) && txtamount2.Length > 0) {
    //If txtamount1 > 0 then "1" . If txtamount2 >0 then "2" (For your condition) if(Convert.ToInt32(txtamount1.Text)>0 && Convert.ToInt32(txtamount2.Text)>0 )
    {
    txtamount1.Text="1";
    txtamoiunt2.Text="2";
    }
    }

    Thank you

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 24, 2019 6:57 AM

All replies

  • User-1038772411 posted

    Hello jsshivalik,

    Try with this

    //Checking conditions
    if (txtamount1!=null && !string.IsNullOrWhiteSpace(txtamount1) && txtamount1.Length > 0 && txtamount2!= null && !string.IsNullOrWhiteSpace(txtamount2) && txtamount2.Length > 0) {
    //If txtamount1 > 0 then "1" . If txtamount2 >0 then "2" (For your condition) if(Convert.ToInt32(txtamount1.Text)>0 && Convert.ToInt32(txtamount2.Text)>0 )
    {
    txtamount1.Text="1";
    txtamoiunt2.Text="2";
    }
    }

    Thank you

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 24, 2019 6:57 AM
  • User288213138 posted

    Hi jsshivalik,

    You can use jQuery to get the values of textboxes and then judge their values.

    The code:

    <div>
                <asp:TextBox ID="txtamount1" runat="server"></asp:TextBox>
                <asp:TextBox ID="txtamount2" runat="server"></asp:TextBox>
            </div>
    <script>
            $(document).ready(function () {
                $('#txtamount2').blur(function () {
                    var t1 = $("#txtamount1").val();
                    var t2 = $("#txtamount2 ").val();
                    if (t1 > 0 & t2 > 0) {
                        alert(t1);
                        alert(t2);
                        
                    }           
                });
            })
            
        </script>
    

    The result:

    Best regards,

    Sam

    Monday, June 24, 2019 9:39 AM