Hi all i am writing calculation of varius asp textbox controls. I want my calculation being done with keypress event. Below code i am using but not working
.aspx page
<asp:TextBox ID="txtMaintCost onkeypress="calculateFinanceDetail(); return false;" runat="server"></asp:TextBox>
.js file
function calculateFinanceDetail() {
var txtMaintCost = $('input[id$=txtMaintCost]').val();
var txtInstallCost = $('input[id$=txtInstallCost]').val();
var txtFreightCost = $('input[id$=txtFreightCost]').val();
}
its not calling javascript function on keypress event…
If anyone have any idea than please help me in this..
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Missing " at the end of id of textbox.
Change
<asp:TextBox ID="txtMaintCost onkeypress="calculateFinanceDetail(); return false;" runat="server"></asp:TextBox>
To
<asp:TextBox ID="txtMaintCost" onkeypress="calculateFinanceDetail(); return false;" runat="server"></asp:TextBox>
Try using the ClientID of server controls. You might not having static ids for server side controls. You do not have to use wild cards if you have fixed ids.
function calculateFinanceDetail() {
var txtMaintCost = $('input[id=<%=txtMaintCost.ClientID%>]').val();
var txtInstallCost = $('input[id=<%=txtInstallCost.ClientID%>]').val();
var txtFreightCost = $('input[id=<%=txtFreightCost.ClientID%>]').val();
}
Method 2
You’re missing quotes here ID="txtMaintCost onkeypress=", it should be ID="txtMaintCost" "onkeypress="
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0