How to make keypress event of asp textbox?
54,124
Solution 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();
}
Solution 2
You're missing quotes here ID="txtMaintCost onkeypress="
, it should be ID="txtMaintCost" "onkeypress="
Author by
user968441
Updated on July 09, 2022Comments
-
user968441 almost 2 years
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..