if else condition on event change dropdown

Analyst_SQL 3,531 Reputation points
2023-03-17T20:13:40.8266667+00:00

I want if else condition between two label on dropdown change event, if both have same value then alert message otherwise qty meet else wrong

 <script type="text/javascript">
        $(document).ready(function () {
            $("#select2-1").change(function () {
                //console.log($("#select2-1").val());

                var orderId = $("#select2-1").val();
                if (orderId != "") {
                    GetOrderno(orderId);
                    GetProduceqty(orderId);
                    GetPackedqty(orderId);
                    GetOrdernoID(orderId);
                }
                else {
                    $("#quantity-label-2").text("QTY");
                    $("#orderqty").empty();
                }
            });
        });


  function GetOrderno(orderId) {

            $.ajax({
                async: true,
                type: 'GET',
                dataType: 'JSON',
                url: '/OrderPack/GetOrderno',
                data: { orderId: orderId },
                success: function (data) {
                    console.log(data);
                    //populate the didden field
                    $("#orderqty").val(data.orderqty);
                    //populate the label
                    $("#quantity-label-2").text(data.orderqty);
                },
                error: function () {
                    alert("There is some problem to get.");
                }
            });
        }

        function GetProduceqty(orderId) {

            $.ajax({
                async: true,
                type: 'GET',
                dataType: 'JSON',
                url: '/OrderPack/GetProduceqty',
                data: { orderId: orderId },
                success: function (data) {
                    console.log(data);
                    //populate the didden field
                    $("#prdqty").val(data.prdqty);
                    //populate the label
                    $("#quantity-label-3").text(data.prdqty);
                },
                error: function () {
                    alert("There is some problem to get.");
                }
            });
        }

        function GetPackedqty(orderId) {

            $.ajax({
                async: true,
                type: 'GET',
                dataType: 'JSON',
                url: '/OrderPack/GetPackedqty',
                data: { orderId: orderId },
                success: function (data) {
                    console.log(data);
                    //populate the didden field
                    $("#packQty").val(data.packQty);
                    //populate the label
                    $("#quantity-label-4").text(data.packQty);
                },
                error: function () {
                    alert("There is some problem to get.");
                }
            });
        }
        function GetOrdernoID(orderId) {
            $.ajax({
                async: true,
                type: 'GET',
                dataType: 'JSON',
                url: '/OrderPack/GetOrdernoID',
                data: { orderId: orderId },
                success: function (data) {
                    console.log(data);
                    //populate the didden field
                    $("#Orderno").val(data.OrderNo);
                    //populate the label
                    $("#Orderno-label-5").text(data.OrderNo);
                },
                error: function () {
                    alert("There is some problem to get.");
                }
            });
        }

  @Html.LabelFor(model => model.OrderNo, "Select Order", htmlAttributes: new { @class = "control-label col-md-3" })

                @Html.DropDownList("orderId", (SelectList)ViewBag.OrderNo, "Select", htmlAttributes: new { @class = "form-control", @id = "select2-1" })

                @Html.ValidationMessageFor(model => model.OrderNo, "", new { @class = "text-danger" })

            </div>

     


            <div class="col-md-4" style="background-color:lightskyblue; text-align:center;font-family:'Times New Roman'">
                <h3 style="font-family:'Times New Roman'">Order Status</h3>
                @Html.LabelFor(model => model.orderqty, "Order", htmlAttributes: new { @class = "control-label col-md-2" })
                @Html.LabelFor(model => model.prdqty, "Produce", htmlAttributes: new { @class = "control-label col-md-2" })
                @Html.LabelFor(model => model.packQty, "Packed", htmlAttributes: new { @class = "control-label col-md-2" })
                <br />

                @Html.LabelFor(model => model.orderqty, "Order", htmlAttributes: new { @class = "control-label  col-md-2", @id = "quantity-label-2" })
                @Html.HiddenFor(Model => Model.orderqty)



                @Html.LabelFor(model => model.prdqty, "Produce", htmlAttributes: new { @class = "control-label  col-md-2", @id = "quantity-label-3" })
                @Html.HiddenFor(Model => Model.prdqty)

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,247 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,206 questions
{count} votes

Accepted answer
  1. Pollibondu 75 Reputation points
    2023-03-19T10:49:53.79+00:00
    $.when(GetOrderno(orderId),
           GetProduceqty(orderId),
           GetPackedqty(orderId),
           GetOrdernoID(orderId))
      .then(function() {
          // do test here
      });
    

2 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,041 Reputation points
    2023-03-18T14:58:46.8833333+00:00

    Your question is not clear. If you want to check the return values of the ajax call, then convert the the functions to return a promise

    function GetOrderno(orderId) {
    
              return  $.ajax({
    
    

    an use a when.

     $.when(GetOrderno(orderId),
           GetProduceqty(orderId),
           GetPackedqty(orderId),
           GetOrdernoID(orderId))
      .then(function() {
          // do test here
      });
    

    or use await

    1 person found this answer helpful.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more