compare two textbox in asp.net javascript

RAVI 936 Reputation points
2023-04-18T10:55:22.33+00:00

hello this is my query i want to compare textbox22 is greater then textbox23 before insert data how to do so using my below code

    
    <script type="text/javascript">
        var data = [];
        $(document).ready(function () {
            $('.movedata').change(function (e) {
                      var IssueBatch = document.getElementById('<%=TextBox11.ClientID%>').value;  
                      var Process = document.getElementById('<%=FP1.ClientID%>').value;  
                        var Name =  $('#<%=DropDownList26.ClientID%> option:selected').text(); 
                      var  Rate =  document.getElementById('<%=TextBox9.ClientID%>').value;   
                       var TP = document.getElementById('<%=TextBox5.ClientID%>').value; 
                        var Qty =  document.getElementById('<%=TextBox23.ClientID%>').value;  
                          var Temp =  document.getElementById('<%=TextBox1.ClientID%>').value;  
                        var Time = document.getElementById('<%=TextBox10.ClientID%>').value; 
                         var ReqNo = document.getElementById('<%=TextBox2.ClientID%>').value; 
                            var Types = document.getElementById('<%=Label4.ClientID%>').innerHTML; 
                            var Remarks = 'Extra-Add'; 
                                var BatchNo = document.getElementById('<%=Label2.ClientID%>').innerHTML; 
                                    var ST = document.getElementById('<%=Label7.ClientID%>').innerHTML; 
                            var SC = document.getElementById('<%=Label8.ClientID%>').innerHTML; 
                   var DT = document.getElementById('<%=TextBox3.ClientID%>').value; 
                     var RP = document.getElementById('<%=TextBox22.ClientID%>').value; 
                       var RQ = document.getElementById('<%=TextBox23.ClientID%>').value; 
                          var GODOWN = document.getElementById('<%=Label4.ClientID%>').innerHTML; 
                     
                   
                   
                var item = {
                 IssueBatch: document.getElementById('<%=TextBox11.ClientID%>').value,
                  Process:  document.getElementById('<%=FP1.ClientID%>').value,
                    Name:  $('#<%=DropDownList26.ClientID%> option:selected').text(), 
                     Rate: document.getElementById('<%=TextBox9.ClientID%>').value,
                       TP: document.getElementById('<%=TextBox5.ClientID%>').value, 
                    Qty: document.getElementById('<%=TextBox23.ClientID%>').value,
                    Temp: document.getElementById('<%=TextBox1.ClientID%>').value,
                     Time: document.getElementById('<%=TextBox10.ClientID%>').value,   
                    ReqNo: document.getElementById('<%=TextBox2.ClientID%>').value,   
                     Types: document.getElementById('<%=Label4.ClientID%>').innerHTML,   
                      Remarks: 'Extra-Add',   
                      BatchNo: document.getElementById('<%=Label2.ClientID%>').innerHTML,  
                       ST: document.getElementById('<%=Label7.ClientID%>').innerHTML,  
                       SC: document.getElementById('<%=Label8.ClientID%>').innerHTML,  
                        DT: document.getElementById('<%=TextBox3.ClientID%>').value, 
                          RP: document.getElementById('<%=TextBox22.ClientID%>').value, 
                            RQ: document.getElementById('<%=TextBox23.ClientID%>').value, 
                             GODOWN: document.getElementById('<%=Label14.ClientID%>').innerHTML, 
                           
               
                };
                data.push(item);
                item.index = data.length -1;
                
              
                $("#<%=GridView1.ClientID%> tbody").append(
               "<tr data-index='" + (data.length-1) + "'><td>" 
               +  document.getElementById('<%=TextBox11.ClientID%>').value + "</td><td>" 
               + document.getElementById('<%=FP1.ClientID%>').value 
               + "</td><td>" +  $('#<%=DropDownList26.ClientID%> option:selected').text() 
               + "</td><td>" + document.getElementById('<%=TextBox9.ClientID%>').value 
              + "</td><td>" + document.getElementById('<%=TextBox5.ClientID%>').value  
               + "</td><td>" + document.getElementById('<%=TextBox23.ClientID%>').value  
                + "</td><td>" +document.getElementById('<%=TextBox1.ClientID%>').value  
                 + "</td><td>" +document.getElementById('<%=TextBox10.ClientID%>').value  
                  + "</td><td>" +document.getElementById('<%=TextBox22.ClientID%>').value  
                   + "</td><td>" +document.getElementById('<%=TextBox23.ClientID%>').value
                    + "</td><td>" +document.getElementById('<%=Label14.ClientID%>').innerHTML  

                  
               + "</td>" + "<td><input type='button' value='Delete' /></td>" + "</tr>")



                $("#<%=GridView1.ClientID%> tbody tr:last input").click(function () {
                   
                    $(this).parent("td").parent("tr").remove();
                    var index = $(this).parent("td").parent("tr").data("index");
                    data = data.filter(function (ele) {
                       
                        if (ele.index == index) {
                            return false;
                        }
                        return true;
                    })                                
                })

               $('#<%=DropDownList26.ClientID%> option:first').prop("selected",true);
                $('#<%=TextBox9.ClientID%>').val("");
                 $('#<%=TextBox23.ClientID%>').val("");
                  $('#<%=TextBox1.ClientID%>').val("");
                   $('#<%=TextBox10.ClientID%>').val("");
                     $('#<%=TextBox22.ClientID%>').val("");
            });

            $("#Button1").click(function () {

                 $.ajax({
                    type: 'POST',
                    contentType: "application/json; charset=utf-8",
                     url: 'Extra_Consume.aspx/InsertData',
                     data: JSON.stringify({myModels:data}),                   
                     success: function (e) {
                         alert("Card Saved Sucessfully...");
                         location.reload(true);
                         var redirectWindow = window.open('DyeSlip_seprate_extra.aspx', '_blank');
                                redirectWindow.location;
                       //  window.location.href('','_newtab');
                    },
                    error: function (e) {
                        alert("Error In Page Please Contact Admin...");
                    }
                    
                }); 
        })         
        });    
 

    </script>

Thanking You

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,312 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
902 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 26,516 Reputation points Microsoft Vendor
    2023-04-19T03:07:16.04+00:00

    Hi @RAVI,

    i want to compare textbox22 is greater then textbox23 before insert data

    You can compare the values of the two textboxes before inserting the data.

     $(document).ready(function () {
               
                $("#Button1").click(function () {
                   
                    var RP = document.getElementById('<%=TextBox22.ClientID%>').value; 
                    var RQ = document.getElementById('<%=TextBox23.ClientID%>').value; 
                    if (RP > RQ) {
                        $.ajax({
                            type: 'POST',
                            contentType: "application/json; charset=utf-8",
                            url: 'Extra_Consume.aspx/InsertData',
                            data: JSON.stringify({ myModels: data }),
                            success: function (e) {
                                alert("Card Saved Sucessfully...");
                                location.reload(true);
                                var redirectWindow = window.open('DyeSlip_seprate_extra.aspx', '_blank');
                                redirectWindow.location;
                                //  window.location.href('','_newtab');
                            },
                            error: function (e) {
                                alert("Error In Page Please Contact Admin...");
                            }
    
                        }); 
                    }
                    else {
                        alert("textbox22 must be larger than textbox23")
                    }
                       
                   
                })
            });    
    
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful