locked
ajax funcition cannot display output based on parameters? RRS feed

  • Question

  • User-1026236167 posted
    hello here in my code i want to run ajax functionality the result should be display in the textbox TB_final_amount 
    but when i select product from dropdownlist and enter quantity then nothing can display in TB_final_amount ihave only
    one script and i want to run this on only one function

    where is problem in my code please solve them



    aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm11.aspx.cs" Inherits="testing.WebForm11" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <script src="bower_components/jquery/dist/jquery.min.js"></script> <!-- Bootstrap Core JavaScript --> <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> <!-- Metis Menu Plugin JavaScript --> <script src="bower_components/metisMenu/dist/metisMenu.min.js"></script> <!-- DataTables JavaScript --> <script src="bower_components/datatables/media/js/jquery.dataTables.js"></script> <script src="bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script> <!-- Custom Theme JavaScript --> <script src="dist/js/sb-admin-2.js"></script> <link href="dist/css/styles.css" rel="stylesheet" /> <script> $(document).ready(function () { $("#TB_price, #TB_qty").keyup(function () { $("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val()); }); $("#TB_discount_value, #TB_final_amount,#TB_price, #TB_qty, #DD_tax_type, #<%=TB_tax_percentage.ClientID %>, #<%=DD_discount_wise.ClientID %>").change(function () { parseFloat($("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val())); if ($('#<%=DD_discount_wise.ClientID %>').val() == "Percentage Wise") { var main = parseFloat($('#TB_final_amount').val()); var disc = parseFloat($('#TB_discount_value').val() || 0); if (disc != 0) { var dec = (disc / 100).toFixed(2); var mult = main * dec; var discont = main - mult; $('#TB_final_amount').val(discont); } } else if ($('#<%=DD_discount_wise.ClientID %>').val() == "Amount Wise") { var main = parseFloat($('#TB_final_amount').val()); var disc = parseFloat($('#TB_discount_value').val() || 0); var mult = main - disc; $('#TB_final_amount').val(mult); } else if ($('#<%=DD_discount_wise.ClientID %>').val() == "Unit Wise") { var mult = parseFloat($("#TB_discount_value").val() * $("#TB_qty").val()); var main = parseFloat($("#TB_final_amount").val()); mult1 = main - mult; //var main = parseFloat($('#TB_final_amount').val()); //var disc = parseFloat($('#TB_discount_value').val() || 0); //var mult = main - disc; $('#TB_final_amount').val(mult1); } else if ($('#<%=DD_discount_wise.ClientID %>').val() == 0) { $('#TB_discount_value').val(0); } //}) else if $("#<%=TB_tax_percentage.ClientID %>").val() == "12" { //parseFloat($("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val())); //if ($(this).val() == "12") { var main = parseFloat($('#TB_final_amount').val()); var disc = parseFloat($('#TB_tax_percentage').val()); var dec = (disc / 100).toFixed(2); var mult = main * dec; var discont = main + mult; $('#TB_final_amount').val(discont); } else if $("#<%=TB_tax_percentage.ClientID %>").val() == "18" { parseFloat($("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val())); var main = parseFloat($('#TB_final_amount').val()); var disc = parseFloat($('#TB_tax_percentage').val()); var dec = (disc / 100).toFixed(2); var mult = main * dec; var discont = main + mult; $('#TB_final_amount').val(discont); } else if ($('#<%=DD_tax_type.ClientID %>').val() == 0) { $('#TB_tax_percentage').val(0); } }) }); </script> <%-- <asp:ToolkitScriptManager ID="TC1" runat="server" />--%> <asp:ScriptManager ID="TC1" runat="server"></asp:ScriptManager> <div class="panel-body"> <div class="row"> <div class="col-sm-4"> <label>Select Party</label> <asp:DropDownList ID="DD_party" runat="server" CssClass="form-control" AutoPostBack="true" OnSelectedIndexChanged="DD_party_SelectedIndexChanged" DataTextField="DataTextField" DataValueField="DataValueField" /> </div> <div class="col-sm-2"> <label>Bill Date</label> <asp:TextBox ID="TB_purchase_date" runat="server" CssClass="form-control" AutoCompleteType="Disabled" /> <asp:CalendarExtender ID="CC1" runat="server" TargetControlID="TB_purchase_date" /> </div> <div class="col-sm-2"> <label>Bill No</label> <asp:TextBox ID="TB_bill_no" runat="server" CssClass="form-control" AutoCompleteType="Disabled" /> </div> <div class="col-sm-2"> <label>Mode</label> <asp:DropDownList ID="DD_bill_mode" runat="server" CssClass="form-control" > <asp:ListItem>Credit</asp:ListItem> <asp:ListItem>Cash</asp:ListItem> </asp:DropDownList> </div> <div class="col-sm-2"> <label>GST Type</label> <input type="text" ID="TB_gst_type" runat="server" Class="form-control" readonly/> </div> </div> <div class="row"> <br /> </div> <ol class="breadcrumb mb-1" style="padding:.05rem 1rem; background-color:#007bff; color:white; "> <li class="breadcrumb-item active" style="color:white;">Product Information</li> </ol> <div class="row"> <div class="col-sm-6"> <label>Select Product</label> <asp:DropDownList ID="DD_product" runat="server" CssClass="form-control" DataTextField="DataTextField" DataValueField="DataValueField" AutoPostBack="true" OnSelectedIndexChanged="DD_product_SelectedIndexChanged" > </asp:DropDownList> </div> <div class="col-sm-2"> <label>Unit</label> <asp:DropDownList ID="DD_unit" runat="server" Enabled="false" CssClass="form-control" DataTextField="DataTextField" DataValueField="DataValueField" > <asp:ListItem>Pcs</asp:ListItem> </asp:DropDownList> </div> <div class="col-sm-2"> <label>Size</label> <asp:DropDownList ID="DD_size" runat="server" CssClass="form-control" DataTextField="DataTextField" DataValueField="DataValueField" > <asp:ListItem>Pcs</asp:ListItem> </asp:DropDownList> </div> <div class="col-sm-2"> <label>Color</label> <asp:DropDownList ID="DD_color" runat="server" CssClass="form-control" DataTextField="DataTextField" DataValueField="DataValueField" > <asp:ListItem>Pcs</asp:ListItem> </asp:DropDownList> </div> <div class="col-sm-2"> <label>Qty</label> <asp:TextBox ID="TB_qty" runat="server" CssClass="form-control" AutoCompleteType="Disabled" onkeyup="total()" /> </div> <div class="col-sm-2"> <label>Price</label> <asp:TextBox ID="TB_price" runat="server" CssClass="form-control" AutoCompleteType="Disabled" onkeyup="total()"/> </div> <div class="col-sm-2"> <label>Dis. Type</label> <asp:DropDownList ID="DD_discount_wise" runat="server" CssClass="form-control" onkeyup="total()" onkeydown="total()" onchange="total()"> <asp:ListItem>Select</asp:ListItem> <asp:ListItem>Percentage Wise</asp:ListItem> <asp:ListItem>Amount Wise</asp:ListItem> <asp:ListItem>Unit Wise</asp:ListItem> </asp:DropDownList> </div> <div class="col-sm-2"> <label>Disc. Value</label> <asp:TextBox ID="TB_discount_value" runat="server" AutoCompleteType="Disabled" Text="0" CssClass="form-control" onkeyup="total()" placeholder="Enter Percentage or Amount" /> </div> <div class="col-sm-2"> <label>Tax Type</label> <asp:DropDownList ID="DD_tax_type" runat="server" CssClass="form-control" onkeyup="total()" onkeydown="total()" onchange="total()"> <asp:ListItem>Select</asp:ListItem> <asp:ListItem>Inclusive</asp:ListItem> <asp:ListItem>Exclusive</asp:ListItem> </asp:DropDownList> </div> <div class="col-sm-2"> <label>Tax %</label> <asp:DropDownList ID="TB_tax_percentage" runat="server" CssClass="form-control" DataTextField="DataTextField" DataValueField="DataTextField" placeholder="Enter Percentage" onkeyup="total()" onkeydown="total()" onchange="total()"/> </div> </div> <div class="row"> <div class="col-sm-2"> <label>Final Amt.</label> <input ID="TB_final_amount" runat="server" Class="btn btn-primary" type="text" readonly Text="0" /> </div> <div class="col-sm-1"> </div> <div class="col-sm-2"> <label>Add Product</label><br /> <asp:Button ID="BT_add" runat="server" Text="Add +" CssClass="btn btn-primary" OnClick="BT_add_Click" /> </div> </div> <div class="row"> <div class="col-sm-12"> <br /> <asp:Panel ID="P1" runat="server" ScrollBars="Auto" Height="300px" Width="100%"> <asp:GridView ID="Gv1" runat="server" AutoGenerateColumns="false" Width="100%" EmptyDataText="No Products Added." DataKeyNames="product_name,unit,qty,price,total,discountype,discountvalue,discountamount,taxableamount,taxableactualamount,taxtype ,taxpercentage,igstamount,cgstamount,sgstamount,finalamount,size,color,product_name_id,unit_id,size_id,color_id,igst_percentage,cgst_percentage,sgst_percentage" CssClass="table table-striped table-bordered table-hover" HeaderStyle-BackColor="#0063a4" HeaderStyle-ForeColor="White" > <Columns> <asp:TemplateField HeaderText="Sr. No."> <ItemTemplate> <%# Container.DataItemIndex+1 %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Product Information"> <ItemTemplate> <%# Eval("product_name") %><br /> Unit : <%# Eval("unit") %> <br /> Size : <%# Eval("size") %><br /> Color : <%# Eval("color") %><br /> <%# Eval("qty") %>*<%# Eval("price") %>= Total ( <%# Eval("total") %> ) </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Discount Information"> <ItemTemplate> Discount Type : <%# Eval("discountype") %><br /> Discount Value : <%# Eval("discountvalue") %><br /> Discount Total : <%# Eval("discountamount") %> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Tax Information"> <ItemTemplate> Tax Type : <%# Eval("taxtype") %><br /> Actual Taxable Amount : <%# Eval("taxableactualamount") %><br /> Tax Percentage : <%# Eval("taxpercentage") %><br /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Tax Amount"> <ItemTemplate> IGST : <%# Eval("igstamount") %><br /> CGST : <%# Eval("cgstamount") %><br /> SGST : <%# Eval("sgstamount") %><br /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Final Amount"> <ItemTemplate> Final : <%# Eval("finalamount") %><br /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </asp:Panel> </div> </div> </div> </form> </body> </html> cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; namespace testing { public partial class WebForm11 : System.Web.UI.Page { DataAcc dataAcc = new DataAcc(); public void ViewStatetable() { DataTable DT = new DataTable(); DT.Columns.Add("product_name"); DT.Columns.Add("unit"); DT.Columns.Add("qty"); DT.Columns.Add("price"); DT.Columns.Add("total"); DT.Columns.Add("discountype"); DT.Columns.Add("discountvalue"); DT.Columns.Add("discountamount"); DT.Columns.Add("taxableamount"); DT.Columns.Add("taxableactualamount"); DT.Columns.Add("taxtype"); DT.Columns.Add("taxpercentage"); DT.Columns.Add("igstamount"); DT.Columns.Add("cgstamount"); DT.Columns.Add("sgstamount"); DT.Columns.Add("finalamount"); DT.Columns.Add("size"); DT.Columns.Add("color"); DT.Columns.Add("product_name_id"); DT.Columns.Add("unit_id"); DT.Columns.Add("size_id"); DT.Columns.Add("color_id"); DT.Columns.Add("igst_percentage"); DT.Columns.Add("cgst_percentage"); DT.Columns.Add("sgst_percentage"); ViewState["DT"] = DT as DataTable; } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { TB_purchase_date.Text = System.DateTime.UtcNow.ToShortDateString(); DD_party.Focus(); dataAcc.GetParty(DD_party, Convert.ToDecimal(Session["tbl_master_party_id"].ToString())); dataAcc.GetProduct(DD_product, Convert.ToDecimal(Session["tbl_master_party_id"].ToString())); dataAcc.GetMasters(DD_unit, "UOM", Convert.ToDecimal(Session["tbl_master_party_id"].ToString())); dataAcc.GetMasters(DD_size, "Size", Convert.ToDecimal(Session["tbl_master_party_id"].ToString())); dataAcc.GetMasters(DD_color, "Color", Convert.ToDecimal(Session["tbl_master_party_id"].ToString())); dataAcc.GetMasters(TB_tax_percentage, "Gst", Convert.ToDecimal(Session["tbl_master_party_id"].ToString())); Gv1.DataSource = null; Gv1.DataBind(); ViewStatetable(); } } protected void BT_add_Click(object sender, EventArgs e) { if (DD_party.SelectedIndex <= 0) { Response.Write("<script language=javascript>alert('Please select party.')</script>"); return; } if (string.IsNullOrEmpty(TB_purchase_date.Text)) { Response.Write("<script language=javascript>alert('Please fill date.')</script>"); return; } if (string.IsNullOrEmpty(TB_bill_no.Text)) { Response.Write("<script language=javascript>alert('Please fill bill no.')</script>"); return; } if (DD_unit.SelectedIndex <= 0) { Response.Write("<script language=javascript>alert('Please fill bill no.')</script>"); return; } if (DD_product.SelectedIndex <= 0) { Response.Write("<script language=javascript>alert('Please fill bill no.')</script>"); return; } if (DD_size.SelectedIndex <= 0) { Response.Write("<script language=javascript>alert('Please fill bill no.')</script>"); return; } if (DD_color.SelectedIndex <= 0) { Response.Write("<script language=javascript>alert('Please fill bill no.')</script>"); return; } if (string.IsNullOrEmpty(TB_qty.Text)) { Response.Write("<script language=javascript>alert('Please fill qty.')</script>"); return; } if (string.IsNullOrEmpty(TB_price.Text)) { Response.Write("<script language=javascript>alert('Please fill price.')</script>"); return; } if (ViewState["DT"] != null) { DataTable DT = ViewState["DT"] as DataTable; decimal tax = 0; string party_type = "Outer-State"; using (Entities ctx = new Entities()) { decimal party_id = Convert.ToDecimal(DD_party.SelectedValue.ToString()); var cust = (from a in ctx.tbl_party where a.tbl_id == party_id select a).FirstOrDefault(); if (cust != null) { party_type = cust.gst_type; } } tax = Convert.ToDecimal(TB_tax_percentage.SelectedItem.Text.Replace("Select", "0")); decimal igst = 0, cgst = 0, sgst = 0; if (party_type == "Inner-State") { tax = Convert.ToDecimal(TB_tax_percentage.SelectedItem.Text.Replace("Select", "0")); tax = Math.Round(tax / 2, 2); cgst = tax; sgst = tax; } else { igst = tax; } DT.Rows.Add(DD_product.SelectedItem.Text, DD_unit.SelectedItem.Text.Replace("Select", "N/A"), TB_qty.Text, TB_price.Text, DD_discount_wise.SelectedItem.Text.Replace("Select", "N/A"), TB_discount_value.Text, DD_tax_type.SelectedItem.Text.Replace("Select", "N/A"), TB_tax_percentage.SelectedItem.Text.Replace("Select", "N/A"), TB_final_amount.Value.ToString(), DD_size.SelectedItem.Text.Replace("Select", "N/A"), DD_color.SelectedItem.Text.Replace("Select", "N/A"), DD_product.SelectedValue.ToString(), DD_unit.SelectedValue.ToString(), DD_size.SelectedValue.ToString(), DD_color.SelectedValue.ToString(), igst.ToString(), cgst.ToString(), sgst.ToString()); Gv1.DataSource = DT; Gv1.DataBind(); DD_product.Focus(); } } protected void DD_party_SelectedIndexChanged(object sender, EventArgs e) { using (Entities ctx = new Entities()) { decimal party_id = Convert.ToDecimal(DD_party.SelectedValue.ToString()); var cust = (from a in ctx.tbl_party where a.tbl_id == party_id select a).FirstOrDefault(); if (cust != null) { TB_gst_type.Value = cust.gst_type; TB_purchase_date.Focus(); } } } protected void DD_product_SelectedIndexChanged(object sender, EventArgs e) { decimal product_id = Convert.ToDecimal(DD_product.SelectedValue.ToString()); using (Entities ctx = new Entities()) { var cust = (from a in ctx.tbl_products where a.tbl_id == product_id select a).FirstOrDefault(); if (cust != null) { DD_unit.SelectedIndex = DD_unit.Items.IndexOf(DD_unit.Items.FindByValue(cust.uom)); TB_price.Text = cust.wsp.ToString(); DD_size.Focus(); } } } } }

    Saturday, October 3, 2020 2:04 PM

All replies

  • User475983607 posted

    Your code is very confusing.   I do not see any AJAX in the code.   The DD_Product dropdown is set to auto post back which causes a page refresh. There is nothing in the code behind selected  index change handlers that sets TB_final_amount.  At this point, I'm not sure how to help you.

    I recommend running your code through the debugger.  

    Saturday, October 3, 2020 5:19 PM
  • User-1026236167 posted

    1) sorry sir this is jquery based code as u see in script

    2) sir output is not display in the TB_final_amount.  textbox 

    3) you should see on your behalf why output is not display based an all <script> all code  </script>

    Sunday, October 4, 2020 5:22 AM
  • User475983607 posted

    1) sorry sir this is jquery based code as u see in script

    2) sir output is not display in the TB_final_amount.  textbox 

    3) you should see on your behalf why output is not display based an all <script> all code  </script>

    Again, the DD_Product dropdown causes a post back.

    <asp:DropDownList ID="DD_product" runat="server" CssClass="form-control" DataTextField="DataTextField" 
        DataValueField="DataValueField" AutoPostBack="true" OnSelectedIndexChanged="DD_product_SelectedIndexChanged"  >
    </asp:DropDownList>

    The OnSelectedIndexChanged handler does not set the TB_final_amount input.  

            protected void DD_product_SelectedIndexChanged(object sender, EventArgs e)
            {
                decimal product_id = Convert.ToDecimal(DD_product.SelectedValue.ToString());
                using (Entities ctx = new Entities())
                {
                    var cust = (from a in ctx.tbl_products
                                where a.tbl_id == product_id
                                select a).FirstOrDefault();
    
                    if (cust != null)
                    {
                        DD_unit.SelectedIndex = DD_unit.Items.IndexOf(DD_unit.Items.FindByValue(cust.uom));
                        TB_price.Text = cust.wsp.ToString();
                        DD_size.Focus();
                    }
                }
            }

    The last thing that happens is the jquery code is overwritten because the post back causes a full page refresh.

    It seems like you don't understand how your code works and you are not using the debuggers, Visual Studio and Dev tools, to find the source of the design bug.

    Sunday, October 4, 2020 10:07 AM
  • User-1026236167 posted

    ok sir i tell u case you should run this script this can run successfully and if i comment this code u should see display output  TB_final_amount 

    but if i uncomment this script code result is not calculate in the TB_final_amount 

    i want to run this whole script code in the one function 

    this is my requirement

     <script>
                $(document).ready(function () {
                    $("#TB_price, #TB_qty").keyup(function () {
                        $("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val());
                    });
                    $("#TB_discount_value, #TB_final_amount,#TB_price, #TB_qty, #DD_tax_type, #<%=TB_tax_percentage.ClientID %>, #<%=DD_discount_wise.ClientID %>").change(function () {
                        parseFloat($("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val()));
                        if ($('#<%=DD_discount_wise.ClientID %>').val() == "Percentage Wise") {
                         var main = parseFloat($('#TB_final_amount').val());
                         var disc = parseFloat($('#TB_discount_value').val() || 0);
                        if (disc != 0) {
                            var dec = (disc / 100).toFixed(2);
                            var mult = main * dec;
                            var discont = main - mult;
                            $('#TB_final_amount').val(discont);
                        }
                    }
                        else if ($('#<%=DD_discount_wise.ClientID %>').val() == "Amount Wise") {
                            var main = parseFloat($('#TB_final_amount').val());
                            var disc = parseFloat($('#TB_discount_value').val() || 0);
                            var mult = main - disc;
                            $('#TB_final_amount').val(mult);
                        }
    
                        else if ($('#<%=DD_discount_wise.ClientID %>').val() == "Unit Wise") {
                            var mult = parseFloat($("#TB_discount_value").val() * $("#TB_qty").val());
                            var main = parseFloat($("#TB_final_amount").val());
                            mult1 = main - mult;
                            //var main = parseFloat($('#TB_final_amount').val());
                            //var disc = parseFloat($('#TB_discount_value').val() || 0);
                            //var mult = main - disc;
                            $('#TB_final_amount').val(mult1);
                        }
    
                        else if ($('#<%=DD_discount_wise.ClientID %>').val() == 0) {
                            $('#TB_discount_value').val(0);
    
                        }
                    //})
    
               <%--   else if $("#<%=TB_tax_percentage.ClientID %>").val() == "12" {
                    
                        //parseFloat($("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val()));
                        //if ($(this).val() == "12") {
                            var main = parseFloat($('#TB_final_amount').val());
                            var disc = parseFloat($('#TB_tax_percentage').val());
                            var dec = (disc / 100).toFixed(2);
                            var mult = main * dec;
                            var discont = main + mult;
                            $('#TB_final_amount').val(discont);
    
                  }
    
                  else if $("#<%=TB_tax_percentage.ClientID %>").val() == "18"  {
                            parseFloat($("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val()));
                            var main = parseFloat($('#TB_final_amount').val());
                            var disc = parseFloat($('#TB_tax_percentage').val());
                            var dec = (disc / 100).toFixed(2);
                            var mult = main * dec;
                            var discont = main + mult;
    
                            $('#TB_final_amount').val(discont);
                        }
    
                        else if ($('#<%=DD_tax_type.ClientID %>').val() == 0) {
                            $('#TB_tax_percentage').val(0);
                        }--%>
                    }) 
               
             });
            </script>

    Sunday, October 4, 2020 3:31 PM
  • User475983607 posted

    The code is a mess.  You mentioned AJAX and selecting from the product drop down causes the problem but there is no AJAX anywhere in the code and the DD_Product dropdown does a post back.  This causes a full page refresh.  It seems the steps to reproduce are incorrect?

    Now you are describing the affects of commenting code.  The code in question is a series of conditions based on the current state of inputs.  The community has no idea what the current state of the inputs are or what you expect.  Plus there is a mysterious total() function that is not where to be found.

    As far as I can tell you have no idea how your code works.  I'm not sure how to help you.  Use the standard debugging tools to find the bug(s) in your code. 

    Sunday, October 4, 2020 10:16 PM
  • User1535942433 posted

    Hi prabhjot1313,

    Accroding to your codes,I have found that your comment part have errors.You could add brackets after “else if”. Just like this:

    <script>
                $(document).ready(function () {
                    $("#TB_price, #TB_qty").keyup(function () {
                        $("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val());
                    });
                    $("#TB_discount_value, #TB_final_amount,#TB_price, #TB_qty, #DD_tax_type, #<%=TB_tax_percentage.ClientID %>, #<%=DD_discount_wise.ClientID %>").change(function () {
                        parseFloat($("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val()));
                        if ($('#<%=DD_discount_wise.ClientID %>').val() == "Percentage Wise") {
                         var main = parseFloat($('#TB_final_amount').val());
                         var disc = parseFloat($('#TB_discount_value').val() || 0);
                        if (disc != 0) {
                            var dec = (disc / 100).toFixed(2);
                            var mult = main * dec;
                            var discont = main - mult;
                            $('#TB_final_amount').val(discont);
                        }
                    }
                        else if ($('#<%=DD_discount_wise.ClientID %>').val() == "Amount Wise") {
                            var main = parseFloat($('#TB_final_amount').val());
                            var disc = parseFloat($('#TB_discount_value').val() || 0);
                            var mult = main - disc;
                            $('#TB_final_amount').val(mult);
                        }
    
                        else if ($('#<%=DD_discount_wise.ClientID %>').val() == "Unit Wise") {
                            var mult = parseFloat($("#TB_discount_value").val() * $("#TB_qty").val());
                            var main = parseFloat($("#TB_final_amount").val());
                            mult1 = main - mult;
                            //var main = parseFloat($('#TB_final_amount').val());
                            //var disc = parseFloat($('#TB_discount_value').val() || 0);
                            //var mult = main - disc;
                            $('#TB_final_amount').val(mult1);
                        }
    
                        else if ($('#<%=DD_discount_wise.ClientID %>').val() == 0) {
                            $('#TB_discount_value').val(0);
    
                        }
                    //})
    
               <%--   else if ($("#<%=TB_tax_percentage.ClientID %>").val() == "12") {
                    
                        //parseFloat($("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val()));
                        //if ($(this).val() == "12") {
                            var main = parseFloat($('#TB_final_amount').val());
                            var disc = parseFloat($('#TB_tax_percentage').val());
                            var dec = (disc / 100).toFixed(2);
                            var mult = main * dec;
                            var discont = main + mult;
                            $('#TB_final_amount').val(discont);
    
                  }
    
                  else if ($("#<%=TB_tax_percentage.ClientID %>").val() == "18" ) {
                            parseFloat($("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val()));
                            var main = parseFloat($('#TB_final_amount').val());
                            var disc = parseFloat($('#TB_tax_percentage').val());
                            var dec = (disc / 100).toFixed(2);
                            var mult = main * dec;
                            var discont = main + mult;
    
                            $('#TB_final_amount').val(discont);
                        }
    
                        else if ($('#<%=DD_tax_type.ClientID %>').val() == 0) {
                            $('#TB_tax_percentage').val(0);
                        }--%>
                    }) 
               
             });
            </script>

    I suggest you could press F12 and check whether your codes are right.

    Best regards,

    Yijing Sun

    Monday, October 5, 2020 5:07 AM
  • User-1026236167 posted

    sir as you provide answer

    TB_final_amount can display calculation result but if we select item  like 12,18 from  TB_tax_percentage this cannot
    display calculation result on TB_final_amount

      else if ($("#<%=TB_tax_percentage.ClientID %>").val() == "12") {
                    
                       // parseFloat($("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val()));
                        //if ($(this).val() == "12") {
                            var main = parseFloat($('#TB_final_amount').val());
                            var disc = parseFloat($('#TB_tax_percentage').val());
                            var dec = (disc / 100).toFixed(2);
                            var mult = main * dec;
                            var discont = main + mult;
                            $('#TB_final_amount').val(discont);

                  }

                  else if ($("#<%=TB_tax_percentage.ClientID %>").val() == "18")  {
                          // parseFloat($("#TB_final_amount").val($("#TB_price").val() * $("#TB_qty").val()));
                            var main = parseFloat($('#TB_final_amount').val());
                            var disc = parseFloat($('#TB_tax_percentage').val());
                            var dec = (disc / 100).toFixed(2);
                            var mult = main * dec;
                            var discont = main + mult;

                            $('#TB_final_amount').val(discont);
                        }

                        else if ($('#<%=DD_tax_type.ClientID %>').val() == 0) {
                            $('#TB_tax_percentage').val(0);
                        }

    Monday, October 5, 2020 5:35 AM
  • User1535942433 posted

    Hi prabhjot1313,

    Accroding to your codes,I have created a test and it works.I suggest you could press F12 to check whether your codes have errors.

    You could do just like this:

    1.Run your project and press F12.

    2.Click Source tab.

    3. Breakpoint at the line at  "else if ($("#<%=TB_tax_percentage.ClientID %>").val() == "12")" and " else if ($("#<%=TB_tax_percentage.ClientID %>").val() == "18")" .

    4.Run your project your again and check whether run at these lines.

    Best regards,

    Yijing Sun

    Wednesday, October 7, 2020 7:23 AM
  • User506672522 posted

    mgebhard

    code is a mess.  You mentioned AJAX and selecting from the product drop down causes the problem but there is no AJAX anywhere in the code and the DD_Product dropdown does a post back.  This causes a full page refresh.  It seems the steps to reproduce are incorrect?

    Now you are describing the affects of commenting code router login.  The code in question is a series of conditions based on the current state of inputs.  The community has no idea what the current state of the inputs are or what you expect.  Plus there is a mysterious total() function that is not where to be found.

    As far as I can tell you have no idea how your code works.  I'm not sure how to help you.  Use the standard debugging tools to find the bug(s) in your code.

    I agree the code is a complete mess, but you give a lot of valuable advice, glad to join your community.

    Artur Noubel

    Wednesday, October 28, 2020 12:21 PM
  • User-1026236167 posted

    sir when i used to breakpoint this line is

     Breakpoint at the line at  "else if ($("#<%=TB_tax_percentage.ClientID %>").val() == "12")" and " else if ($("#<%=TB_tax_percentage.ClientID %>").val() == "18")" .

    not display in f12 source tab when i run

    Wednesday, November 4, 2020 6:14 AM