I have written one JavaScript to Calculate the TotalWeight based on two TextBox integer values. I multiplied these two values and displayed in the 3rd TextBox Using JavaScript. But the problem is, I have one radiobuttonlist, in its selectedindexchanged event, the value I got in the 3rd TextBox gets disappeared. How to solve this?
My JavaScript is
<script type="text/javascript">
function TotalWeight()
{
var D1 = document.getElementById('<%=txtD1.ClientID%>');
var SectionWgt = document.getElementById('<%=txtSectionWeight.ClientID%>');
var TotalWgt = 0*1;
TotalWgt = parseFloat(D1.value) * parseFloat(SectionWgt.value);
if(isNaN(TotalWgt))
document.getElementById('<%=txtTotalWgt.ClientID%>').innerText = "0.000";
else
document.getElementById('<%=txtTotalWgt.ClientID%>').innerText = TotalWgt.toFixed(3);
}
</script>
<asp:TextBox ID="txtD1" runat="server" Width="136px" onkeyup="return TotalWeight();"></asp:TextBox>
After you calculate and assign the value to your Total Textbox, then put that value in a
hidden fieldas well, and then on postback reassign that value to the textbox from thehidden Field.