I have a 3 textboxes on a page quantity, price and total . When the quantity and price are entered by the user the total is being calculated directly by using javascript. Below is the code:
function quantity(textvalue) {
var qty = textvalue.value;
var price = document.getElementById('<%=Price.ClientID %>').value;
var Total = Math.round(qty * price * 100) / 100;
document.getElementById('<%=Total.ClientID %>').value = Total;
}
function Price(textvalue) {
var price = textvalue.value;
var qty = document.getElementById('<%=Quantity.ClientID %>').value;
var Total = Math.round(qty * price * 100) / 100;
document.getElementById('<%=Total.ClientID %>').value = Total;
}
<asp:TextBox ID="Quantity" runat="server" onchange="javascript: quantity(this);" CausesValidation="True"></asp:TextBox>
<asp:TextBox ID="Price" runat="server" onchange="javascript: Price(this);" ></asp:TextBox>
<asp:TextBox ID="txtLineItemTotal" runat="server" Width="120px" MaxLength="14" ReadOnly="true"
BackColor="Silver" BorderWidth="2px" style="font-weight: 700">0.00</asp:TextBox>
I also need to validate the value calculated in the total textbox and it should not exceed 100000000000.00.
I am using the below function to achieve this
function TotalChanged() {
var lineitemtotal = document.getElementById('<%=Total.ClientID %>').value;
alert("entered function");
if (lineitemtotal >= 100000000000.00) {
alert("Total cannot exceed 100000000000.00,please re-enter");
}
else
return false;
}
And on Page Load
Total.Attributes.Add("onchange", "{return TotalChanged()};");
But it is not entering the function, please let me know what am I missing...or if I am using the wrong event...trying it for the past 1 day....:(