williamdnapier
williamdnapier

Reputation: 13

ASP .NET Textbox Values & jQuery math

I'd like to do some simple addition and multiplication with ASP .NET textboxes and 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>

Upvotes: 1

Views: 3731

Answers (2)

Vivian River
Vivian River

Reputation: 32380

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);

Upvotes: 1

Abe Miessler
Abe Miessler

Reputation: 85046

Try this:

var total = (parseInt($('#<%= txtQuantity1.ClientID %>').val()) + parseInt($('#<%= txtQuantity2.ClientID %>').val())) * parseInt($('#<%= txtPrice.ClientID %>').val());

Upvotes: 0

Related Questions