Click here to Skip to main content
15,887,841 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
I am using jquery to calculate total price..but it does'nt calculating..displaying value of unit price itself when i enter quantity and total price displayed on label after postback ocuurs on popup..so how i do it without postback?

//jquery

 Collapse | Copy Code
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
  $(".TxtATQuantityATC").blur(function(){
      var price = $(".LblATUPriceATC").text();
      var totalAmount = $(".LblATTotalAmntATC");
      var total = parseInt(this.value) * parseFloat(price);
      totalAmount.text(total);

  });
});
Posted
Comments
Asim Mahmood 18-Feb-13 1:49am    
looking good please debug your js code and this value especially: parseInt(this.value)
Member 9579525 18-Feb-13 1:59am    
thanku..how to debug js code?
Rai Pawan 18-Feb-13 2:17am    
just put a debugger; statement before the statement that you want to start the debugging, then you can debug in IE developer tools - Pawan
Asim Mahmood 18-Feb-13 2:46am    
type debugger; before var price = $(".LblATUPriceATC").text();
and click in IE Tools -> Advanced -> Uncheck Disable script debugging(IE)
Member 9579525 18-Feb-13 8:00am    
getting error "Object Expexcted"...because not getting textbox value

1 solution

I worked with your code as follows.
XML
<body>
    <form id="form1" runat="server">
    <div>
        <div id="divStatus" runat="server">
            <asp:TextBox runat="server" ID="txtATQuantityATC" CssClass="TxtATQuantityATC"></asp:TextBox>
            <asp:Label ID="lblATUPriceATC" runat="server" CssClass="LblATUPriceATC">10</asp:Label >
             <asp:Label ID="lblATTotalAmntATC" runat="server" CssClass="LblATTotalAmntATC">Total Amount:</asp:Label >
        </div>
    </div>
    </form>
</body>


and its javascript code
XML
<script type="text/javascript">
    $(document).ready(function () {
        $(".TxtATQuantityATC").blur(function () {
            var price = $(".LblATUPriceATC").text();
            //alert($(".LblATTotalAmntATC").text());
            var totalAmount = $(".LblATTotalAmntATC");
            var total = parseInt(this.value) * parseFloat(price);
            totalAmount.text(total);

        });
    });
    </script>


I found it is working without postback. Just make sure that your html/asp.net control is same. Let me know if any difference you found. In javascript debug you can use firfox's firebug tool. You can also use console.log/window.alert method for know the run time value.
 
Share this answer
 
Comments
Member 9579525 18-Feb-13 4:31am    
no difference and i am fetching unit price from database on radio button click.. still it is not working..
//my aspx code
<asp:Button CssClass="inputcommon" ID="BtnATAddToCart" runat="server" Text="Add To Cart" onclick="BtnATAddToCart_Click" />
<asp:Button ID="BtnATHidden" style="display:none" runat="server" Text="Button" />


<cc1:ModalPopupExtender ID="MpeAddToCart" runat="server" TargetControlID="BtnATHidden" PopupControlID="PanelAddToCart" >




<asp:Panel ID="PanelAddToCart" runat="server">

<div style="text-align:right; margin-bottom:-15px; margin-right:-10px;">

</div>

<div style="color:Black; color:#fff; background-color:#400a0a;
border-width:2px; border:5px solid silver; padding: 10px; font-size:14px; text-align:left;">



<table cellspacing="15">
<tr>
<td>
Currency Type:
</td>
<td>
<asp:RadioButton ID="RdoATbtnINRATC" Text="INR" runat="server" AutoPostBack="true" OnCheckedChanged="RdoATbtnINRATC_CheckedChanged" GroupName="PRICE" />

</td>
<td>
<asp:RadioButton ID="RdoATbtnDOLLARATC" Text="$" runat="server" AutoPostBack="true" OnCheckedChanged="RdoATbtnDOLLARATC_CheckedChanged" GroupName="PRICE" />
</td>
<td>
<asp:RadioButton ID="RdoATbtnEUROATC" Text="EURO" runat="server" AutoPostBack="true" OnCheckedChanged="RdoATbtnEUROATC_CheckedChanged" GroupName="PRICE" />
</td>
</tr>
<tr>
<td>
Unit Price:
</td>
<td colspan="3">
<asp:Label ID="LblATUPriceATC" CssClass="LblATUPriceATC" runat="server" >
</td>
</tr>
<tr>
<td>
Items Required:
</td>
<td colspan="3">
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Always" runat="server">
<contenttemplate>
<asp:TextBox ID="TxtATQuantityATC" CssClass="TxtATQuantityATC" AutoPostBack="true" runat="server" >


<Triggers>
<asp:AsyncPostBackTrigger ControlID="TxtATQuantityATC" EventName="TextChanged" />

</Triggers>

</td>

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