Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make keypress event of asp textbox?

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..

like image 681
user968441 Avatar asked Aug 23 '12 14:08

user968441


1 Answers

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();
}
like image 108
Adil Avatar answered Oct 09 '22 19:10

Adil