TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Azaad Abbas
NA
221
41.5k
client side calculation
Feb 16 2015 6:15 AM
I want to calculate like below but its calling on any key press and calculation repeating,how to put condiot and where (where) when should clear variables values then it should'nt repeat..
<script type="text/javascript">
function sum() {
var packPrice = document.getElementById('txtAmntToPay').value;
var noOfCon = document.getElementById('txtNoOfConn').value;
var chargPerCon = document.getElementById('txtChargePerConn').value;
var installCharge = document.getElementById('txtInstallCharge').value;
var discount = document.getElementById('txtDiscount').value;
var final;
if (isNaN(packPrice)) {
packPrice = 0;
}
if (isNaN(noOfCon)) {
noOfCon = 0;
}
if (isNaN(chargPerCon)) {
chargPerCon = 0;
}
if (isNaN(installCharge)) {
installCharge = 0;
}
if (isNaN(discount)) {
discount = 0;
}
// final = parseFloat(packPrice);
var tot = parseInt(noOfCon) * parseInt(chargPerCon);
final = parseInt(packPrice) + parseInt(tot);
final = parseInt(final) + parseInt(installCharge);
final = parseInt(final) - parseInt(discount);
if (!isNaN(final)) {
document.getElementById('txtAmntToPay').value = final;
}
}
</script>
<table width="80%">
<tr>
<td width="20%">
Package Name:<br />
</td>
<td width="20%">
<asp:DropDownList ID="ddlPackName" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlPackName_SelectedIndexChanged" TabIndex="11">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="200">Monthly</asp:ListItem>
<asp:ListItem Value="500">Quarterly</asp:ListItem>
<asp:ListItem Value="1000">HalfYearly</asp:ListItem>
<asp:ListItem Value="2000">Yearly</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<table width="80%">
<tr>
<td width="20%">
No. of Extra Connection:<br />
</td>
<td width="20%">
<asp:TextBox ID="txtNoOfConn" runat="server" onKeyup="sum();">0</asp:TextBox>
</td>
</tr>
</table>
<br />
<table width="80%">
<tr>
<td width="20%">
Charges per Connection(If any):<br />
</td>
<td width="20%">
<asp:TextBox ID="txtChargePerConn" runat="server" onKeyup="sum();">0</asp:TextBox>
</td>
</tr>
</table>
<br />
<table width="80%">
<tr>
<td width="20%">
Installation Charges:<br />
</td>
<td width="20%">
<asp:TextBox ID="txtInstallCharge" runat="server" onKeyup="sum();">0</asp:TextBox>
</td>
</tr>
</table>
<br />
<table width="80%">
<tr>
<td width="20%">
Discount (if any):<br />
</td>
<td width="20%">
<asp:TextBox ID="txtDiscount" runat="server" onKeyup="sum();">0</asp:TextBox>
</td>
</tr>
</table>
<br />
<table width="80%">
<tr>
<td width="20%">
Amount to Pay:<br />
</td>
<td width="20%">
<asp:TextBox ID="txtAmntToPay" runat="server" ReadOnly="True">0</asp:TextBox>
</td>
</tr>
</table>
Reply
Answers (
1
)
how to show uploading size
login wirth facebook