Accessing Controls In Javascript/jquery Functions
i am facing a problem in Javascript and JQuery when i call a function on the 'onblur' event of the textbox to multiply its value to another value in other textbox the code works fi
Solution 1:
I've modified your "onblur" function call and javascript function and tested. It works well now. Please find the below Child Page and let me know:
<divclass="row"><divclass="col-md-4"><asp:TextBoxID="txtquan1"runat="server"onblur="funAmount(this.id.replace('txtquan1',''), 'txtquan1','txtatthe1','lblamnt1')"></asp:TextBox><asp:TextBoxID="txtatthe1"runat="server"onblur="funAmount(this.id.replace('txtatthe1',''),'txtquan1','txtatthe1','lblamnt1')"></asp:TextBox><asp:Labelrunat="server"ID="lblamnt1"Text=""></asp:Label></div></div><scripttype="text/javascript">functionfunAmount(suffix, quantity, amount, totalamt) {
var qty = document.getElementById(suffix + quantity).value;
var amt = document.getElementById(suffix + amount).value;
var total = parseFloat(qty) * parseFloat( isNaN(amt) ? 0 : amt);
document.getElementById(suffix + totalamt).innerText = isNaN(total) ? 0 : total;
//document.getElementById('ddltaxtype').options[0].selected = "true";
}
Solution 2:
Check if this works according to your requirement:
1.Use ClientIDMode="Static" in the Page Directive.
2.Remove suffix from the funAmount, as control ids will not have the master page id appended.
functionfunAmount(quantity, amount, totalamt) {
var qty = document.getElementById(quantity).value;
var amt = document.getElementById(amount).value;
var total = parseFloat(qty) * parseFloat(isNaN(amt) ? 0 : amt);
document.getElementById(totalamt).innerText = isNaN(total) ? 0 : total;
document.getElementById('ddltaxtype').options[0].selected = "true";
}
3.Pass the controls to the function appropriately.Eg:
<asp:TextBoxID="txtquan1"runat="server"onblur="funAmount('txtquan1','txtatthe1','lblamnt1')"></asp:TextBox><asp:TextBoxID="txtatthe1"runat="server"onblur="funAmount('txtquan1','txtatthe1','lblamnt1')"></asp:TextBox>
4.Make sure the correct control ids are passed,from your code i see the value passed for "txtatthe2" is incorrect.
5.You should be using a grid control if your rows are going to grow dynamically!
Post a Comment for "Accessing Controls In Javascript/jquery Functions"