I have a query regarding calling jQuery for textbox onchange event.
in my coding am calling onchange event as
<asp:TextBox ID="txtTotalDeductions" Text="0" runat="server"
ClientIDMode="Static" onChange="Deductions();" ></asp:TextBox>
and I have two div sections as
<div id="Total">1000</div>
and
<div id="NetTotal">0</div>
I need to calculate the "NetTotal" by subtracting the Total - txtTotalDeductions.
and my jQuery for Deductions is
//Calculate deductions.
function Deductions() {
var result = new Object();
result.total = $("#Total").html();
result.totalDeductions = $("#txtTotalDeductions").val();
result.netTotal = result.total - result.totalDeductions;
$('#NetTotal').html(result.netTotal);
}
and when I run the application the error shows like "Microsoft JScript runtime error: 'Deductions' is undefined", and the error lies here ""
can anyone help me out pls.....thanks in advance
remove the OnChange handler
function Deductions() {
var result = new Object();
result.total = $("#Total").html();
result.totalDeductions = $("#txtTotalDeductions").val();
result.netTotal = result.total - result.totalDeductions;
$('#NetTotal').html(result.netTotal);
}
also wrap the code inside the ready handler and attach a change event handler
$(document).ready(function(){
//attach with the id od deductions
$("#txtTotalDeductions").bind("change",Deductions);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With