Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textbox onchange event using jquery causes JScript runtime error: 'Deductions' is undefined

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

like image 500
shanish Avatar asked Dec 12 '22 04:12

shanish


1 Answers

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);

});
like image 166
John x Avatar answered Dec 14 '22 18:12

John x