Click here to Skip to main content
14,640,723 members
Rate this:
Please Sign up or sign in to vote.
See more:
I want to calculate total amount dynamically when user enters quantity...i have displayed unit price on label..showing on popup ..i have used jquery but its not working...

//souce code
<cc1:ModalPopupExtender ID="MpeBuyNow1" runat="server" TargetControlID="BtnATHiddenBuyNow1" PopupControlID="PanelBuyNow1" OkControlID="BtnATNextBNW1" >

                              </cc1:ModalPopupExtender>
                        
                              <asp:Panel ID="PanelBuyNow1" runat="server" Style="display: none; width: 250px; color:Black; background-color:Silver;
                               border-width: 2px; border-color: Black; border-style: solid; padding: 20px;">
                               <table cellpadding="10" cellspacing="10">
                               
                             
                               <tr>
                               <td>
                               Unit Price:
                               </td>
                               <td>
                                   <asp:Label ID="LblATUPriceBNW" runat="server" ></asp:Label>
                               </td>
                               </tr>
                               <tr>
                               <td>
                               Items Required:
                               </td>
                               <td>
                                   <asp:TextBox ID="TxtAtQuantityBNW" runat="server"></asp:TextBox>
                               </td>
                               </tr>
                               <tr>
                               <td>Total Amount Of Transaction:
                               </td>
                               <td>
                                   <asp:Label ID="LblATTotalAmntBNW" CssClass="" runat="server" ></asp:Label>
                               </td>
                               </tr>
                              
                              
                               
                              </asp:Panel>


//jquery
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=TxtATQuantityATC]").val("0");
});
$("[id*=TxtATQuantityATC]").live("change", function () {
if (isNaN(parseInt($(this).val()))) {
$(this).val('0');
} else {
$(this).val(parseInt($(this).val()).toString());
}
});
$("[id*=TxtATQuantityATC]").live("keyup", function () {
if (!jQuery.trim($(this).val()) == '') {
if (!isNaN(parseFloat($(this).val()))) {
var row = $(this).closest("tr");
$("[id*=LblATUPriceATC]", row).html(parseFloat($(".price", row).html()) * parseFloat($(this).val()));
}
} else {
$(this).val('');
}
var grandTotal = 0;
$("[id*=LblATUPriceATC]").each(function () {
grandTotal = grandTotal + parseFloat($(this).html());

});
$("[id*=LblATTotalAmntATC]").html(grandTotal.toString());
});
</script>
Posted
Updated 11-Feb-13 18:17pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Try this

$(document).ready(function()
{
var qtytxt='<%=TxtAtQuantityBNW.ClientID%>';
var amounttxt='<%=LblATTotalAmntBNW.ClientID%>';
var pricetxt='<%=LblATUPriceBNW.ClientID%>';
$('#qtytxt').focusout(function()
{
$('#amounttxt').val()=$('#qtytxt').val()*$('#pricetxt').val();
});
});


Hope this helps
   
Comments
Member 9579525 12-Feb-13 0:40am
   
thank u..amount is not getting dynamically..what shoud i do for it??
Jameel VM 12-Feb-13 0:52am
   
amount is getting while entering the quantity.right?
Member 9579525 12-Feb-13 1:05am
   
i expect this but not getting

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100