1

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>
2
  • @Town Thanks for the formatting assist Commented May 4, 2011 at 16:29
  • no problem :) You're using initialvalue in that code you posted, which doesn't exist. Use value instead and you might have more success, or simply alert(total) at that point to check you're getting the correct calculation. Commented May 4, 2011 at 16:32

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

I'm missing something then, no dice for me.
0

Try this:

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

2 Comments

Trying with parseInt(), no luck yet.
@williamdnapier: initialvalue doesn't exist, it should be simply value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.