ASP .NET Textbox Values & jQuery math
I'd like to do some simple addition and multiplication with ASP .NET textboxes an开发者_运维问答d jQuery, if possible.
Quantity One: <asp:Textbox ID="txtQuantity1" runat="server" />
Quantity Two: <asp:Textbox ID="txtQuantity2" runat="server" />
Total Quantity: <asp:Textbox ID="txtTotalQuantity" runat="server" ReadOnly="true" />
Price: <asp:Textbox ID="txtPrice" runat="server" ReadOnly="true" Text="5.00" />
Total Order: <asp:Textbox ID="txtTotalOrder" runat="server" ReadOnly="true" />
I'd like the user to enter quantity 1 and quantity 2 in the text boxes and the script to add those quantities then multiply by price for total order asynchronously.
Can anyone point me in the right direction? Thanks.
Edit - tried this, no luck:
<script type="text/javascript">
//<![CDATA[
var total = (parseInt($('#<%= txtQuantity1.ClientID %>').val()) + parseInt($('#<%= txtQuantity2.ClientID %>').val())) * parseInt($('#<%= txtPrice.ClientID %>').val()); ct100_BodyContent_txtTotalOrder.initialvalue = total;
//]]>
</script>
You were close. Here's what I got to work:
var total = (parseInt($('#<%= txtQuantity1.ClientID %>').val()) + parseInt($('#<%= txtQuantity2.ClientID %>').val()))
* parseInt($('#<%= txtPrice.ClientID %>').val());
$('#<%=txtTotalOrder.ClientID %>').val(total);
Try this:
var total = (parseInt($('#<%= txtQuantity1.ClientID %>').val()) + parseInt($('#<%= txtQuantity2.ClientID %>').val())) * parseInt($('#<%= txtPrice.ClientID %>').val());
精彩评论